Feature request: support sqlite3_mem_methods.xSize = NULL
(1) By anonymous on 2021-04-15 11:32:09 [link]
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
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: ```c void*my_malloc(int x) { int*h; if(!x) return 0; h=malloc(x+sizeof(int)); if(!h) return 0; *h=x; return h+1; } void my_free(void*x) { int*o=x; if(x) free(o-1); } ``` (Note: This code is untested)
(3) By anonymous on 2023-05-04 14:47:13 in reply to 2 [link]
Just a warning: This kind of remapping should maintain the compiler expectation of the alignment of allocated blocks. Typically, it's more than 4 bytes, like 16. Otherwise, you risk getting a BusError for misaligned accesses. Note that this is possible also in Intel if SSE instructions are used by the compiler.