I use the following code, but does not get the right version string of jemalloc.
size_t size = 1000;
char *ptr = (char *) malloc(size);
mallctl("version", ptr, &size, NULL, 0);
I just got a 4-bits size string, and I printed it out found not the version string.
I think the problem is the version string is a const char*. But if I call with a const char*, what size should I fill in?
You should fill in the size of a
const char *, of course.The “version” parameter is a
const char *, which is four bytes on your platform. This function doesn’t get the version string but actually gets a pointer to the version string. You don’t need to allocate space for the version, just a pointer. Here’s working example code: