Commits

Bruce Mitchener Jr authored 7febb30db2f
AVRO-549. Custom allocator interface. You can now provide a custom allocation function, which the Avro library will use for all of the memory that it obtains. The allocator function prototype is the same one used by the Lua interpreter; it's a generic function that includes the functionality of malloc, realloc, and free. It takes in the old pointer (ptr), the old size (osize), and the new size (nsize) of the buffer. For realloc, all three have real values. For malloc, ptr will be NULL, and osize 0. For free, nsize will be 0. One wrinkle is that we have to be able to provide the allocated size of the buffer when we free it, since we have to provide a value for osize. For most of our allocations, this isn't a problem, since we allocated a fixed-size buffer for a struct of some kind. It's also not a problem for the buffers associated with a bytes or fixed field, since we have the buffer size right there. For strings, however, we have to be more clever; for most cases, our strdup replacement adds additional space to the buffer to store its size. This prevents us from having to add lots of additional size_t fields all over the place. We can't do this in the string datum, however, since the givestring methods need to be able to take in an arbitrary string pointer; this means we can't assume it has our special size prefix. git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1057683 13f79535-47bb-0310-9956-ffa450edef68