pbhushan99 / xxhash

Automatically exported from code.google.com/p/xxhash
Other
0 stars 0 forks source link

Avoiding malloc()/free() API #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It is nice to avoid malloc()s for some application (eg. allocate in stack / 
user defined heap, etc).
So, I propose additional APIs:

// prototype (xxhash.h)
size_t XXH32_calcStateSize();
void* XXH32_reset(void* state_in, unsigned int seed);

// implementation (xxhash.c)
size_t XXH32_calcStateSize() {
    return sizeof(struct XXH_state32_t);
}

void* XXH32_reset(void* state_in, unsigned int seed) {
    ... Same as XXH32_init(), but no malloc() line ...
    return state_in;
}

// usage
void* state = alloca(XXH32_calcStateSize());
XXH32_reset(state, seed);
XXH32_update(state, inputPtr, inputSize);
digest = XXH32_intermediateDigest(state);

Original issue reported on code.google.com by takayuki...@gmail.com on 25 Apr 2013 at 1:17

GoogleCodeExporter commented 8 years ago
Sounds like a good idea.
I'll implement it in the next release.

Original comment by yann.col...@gmail.com on 26 Apr 2013 at 12:19

GoogleCodeExporter commented 8 years ago

Original comment by yann.col...@gmail.com on 26 Apr 2013 at 12:19

GoogleCodeExporter commented 8 years ago

Original comment by yann.col...@gmail.com on 26 Apr 2013 at 12:19

GoogleCodeExporter commented 8 years ago
Hi 

Please find in attached file
a proposed release candidate of xxHahs
which adds your requested features :

int           XXH32_sizeofState();
XXH_errorcode XXH32_resetState(void* state_in, unsigned int seed);
/*
These functions are the basic elements of XXH32_init();
The objective is to allow user application to make its own allocation.

XXH32_sizeofState() is used to know how much space must be allocated by the 
application.
This space must be referenced by a void* pointer.
This pointer must be provided as 'state_in' into XXH32_resetState(), which 
initializes the state.
*/

Original comment by yann.col...@gmail.com on 9 May 2013 at 7:10

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks! xxHash_rc works fine :)

Original comment by takayuki...@gmail.com on 9 May 2013 at 8:03

GoogleCodeExporter commented 8 years ago
Feature added into r28

Original comment by yann.col...@gmail.com on 11 May 2013 at 11:24