On Jul 23, 2009, at 11:16 PM, Zachary Turner wrote:

> I was looking into overriding the sqlite_mem_methods interface to
> specify my own allocator.  The two functions I have a question about
> are these:
>
> int (*xSize)(void*)
> int (*xRoundup)(int size);
>
> I've briefly looked over the source code it *seems* like I can safely
> return 0 from xSize and 'size' from xRoundup, with the only effects
> being that functions such as sqlite_mem_used() will be useless.  Are
> there any more subtle implications of implementing these functions in
> the aforementioned way that I'm missing?

Yes. Returning a copy of the 'size' parameter from xRoundup() will work,
but there are at least a few places in the code that depend on a working
sqlite3DbMallocSize(). Which sometimes needs to call xSize().

> the problem is that I have a 3rd party allocator that is extremely
> fast and implements malloc, free, and realloc, but does not implement
> the other functions.  I can probably implement xRoundup if necessary
> by figuring out their allocation / alignment algorithm and
> re-implementing the alignment portion, but xSize I don't think will be
> possible to implement at all.

Write a wrapper that allocates the requested size plus an 8-byte header
each time an allocation is requested. Use the header space to store the
size of the allocation.

Dan.


> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to