View Single Post
Old 09-14-2022, 01:10 PM  
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 13,637
Default

Quote:
Originally Posted by sockmonkey72 View Post
I've been known to write extensions and REAPER-extended plugins, so this is the kind of technical stuff I like to know about.

So if I were calling GetSetProjectInfo_String() from my extension, I would do something like:

Code:
char *ptr = NULL;
int size = 0;
int tok = realloc_cmd_register_buf(&ptr, &size); // allocate ptr and return initial ptr/size
GetSetProjectInfo_String(NULL, "NEEDS_BIG", ptr, false); // REAPER checks some internal table of registered pointers to see if it can realloc for the data to be returned, doing so as necessary
realloc_cmd_clear(tok); // don't need you anymore
?
That should work, although a more typical usage would be to have ptr/size initially point to a reasonable-sized local buffer. That way no heap allocation occurs if the returned data is small enough to fit in the provided buffer.

Code:
char buf[4096];
char *ptr = &buf;
int size = sizeof(buf);
int tok = realloc_cmd_register_buf(&ptr, &size); // allocate ptr and return initial ptr/size
GetSetProjectInfo_String(NULL, "NEEDS_BIG", ptr, false); // REAPER checks some internal table of registered pointers to see if it can realloc for the data to be returned, doing so as necessary
realloc_cmd_clear(tok); // don't need you anymore
schwa is offline   Reply With Quote