SQLite Forum

Feature request: support sqlite3_mem_methods.xSize = NULL

Feature request: support sqlite3_mem_methods.xSize = NULL

(1) By anonymous on 2021-04-15 11:32:09 [link] [source]

Some platforms do not implement msize() or similar functions. It would be nice if one could override the "common" memory methods, and leave xSize a NULL pointer:

struct sqlite3_mem_methods m = {0};
m.xMalloc  = my_malloc;
m.xFree    = my_free;
m.xRealloc = my_realloc;
sqlite3_config(SQLITE_CONFIG_MALLOC, &m); // error handling intentionally left out

(2) By anonymous on 2021-04-15 18:02:24 in reply to 1 [source]

Note that it is easy to implement that function easily even if your system does not support it; write a wrapper for malloc/realloc/free that adds space to store the size. Example:

void*my_malloc(int x) {
  if(!x) return 0;
  if(!h) return 0;
  return h+1;

void my_free(void*x) {
  if(x) free(o-1);

(Note: This code is untested)