This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial lightweight heap allocator
- Loading branch information
Showing
1 changed file
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,46 @@ | ||
#ifndef __EVHTP_HEAP_H__ | ||
#define __EVHTP_HEAP_H__ | ||
|
||
#endif /* ____ */ | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct evhtp_heap_s; | ||
|
||
typedef struct evhtp_heap_s evhtp_heap; | ||
|
||
/** | ||
* @brief creates a new heap context | ||
* | ||
* @param size the size of the data to be allocated | ||
* @param nelem the number of elements allocated with the size | ||
* | ||
* @return NULL on error | ||
*/ | ||
EVHTP_EXPORT evhtp_heap * evhtp_heap_new(size_t size, size_t elts); | ||
|
||
/** | ||
* @brief returns a single pre-allocated segment of memory from the heap list, | ||
* if there happens to be no entries left, one will be allocated, added to the | ||
* heap and returned. | ||
* | ||
* @param heap | ||
* | ||
* @return a block of data | ||
*/ | ||
EVHTP_EXPORT void * evhtp_heap_alloc(evhtp_heap * heap); | ||
|
||
/** | ||
* @brief removes the data entry, and places it back into a unused queue. | ||
* | ||
* @param heap | ||
* @param d data that was returned from evhtp_heap_alloc() | ||
*/ | ||
EVHTP_EXPORT void evhtp_heap_free(evhtp_heap * heap, void * data); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
|