Memory Ownership SendCardMessage Malloc() Sprintf()

Are you developing an External using the LiveCode Externals SDK?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Memory Ownership SendCardMessage Malloc() Sprintf()

Post by n.allan » Mon Sep 28, 2009 8:41 am

I am writing an exteral which is using SendCardMessage(). I know the ownership of the memory is only passed to rev if you use malloc() etc...

What I want to know is.. If I malloc 100 bytes to a buffer for my message to return and only sprintf about 50 chars into said buffer then SendCardMessage(buffer,result) is the whole 100 bytes owned by revolution or only the 50 bytes that were actually used?

I ask this because in windows task manager, The memory usage of the rev ide keeps climbing when I use my external.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Post by mwieder » Mon Sep 28, 2009 5:56 pm

Neil-

Not sure about this, but I think the best thing to do might be to use istrdup to create a copy of the buffer in rev-manageable memory space and then free the memory you malloced, i.e.,

Code: Select all

int *r_error;
char *rbuffer, *buffer;
buffer = malloc(100);
sprintf(buffer, "%s", whatever);
istrdup(rbuffer, buffer);
free(buffer);
SendCardMessage(rbuffer, &r_error);

Post Reply

Return to “Building Externals”