| 1 | #ifndef ONEWAYALLOC_H |
| 2 | #define ONEWAYALLOC_H 1 |
| 3 | |
| 4 | #include "../libnetdata.h" |
| 5 | |
| 6 | typedef void ONEWAYALLOC; |
| 7 | |
| 8 | ONEWAYALLOC *onewayalloc_create(size_t size_hint); |
| 9 | void onewayalloc_destroy(ONEWAYALLOC *owa); |
| 10 | |
| 11 | // Reset the arena to an empty state without destroying it. Frees every |
| 12 | // page except the head, and rolls the head page's bump pointer back to |
| 13 | // its initial offset so the arena is reusable. Intended for callers that |
| 14 | // do many short bursts of allocations back-to-back (e.g. evaluating all |
| 15 | // the alerts of one host) and want to amortise the mmap/munmap cost of |
| 16 | // create/destroy across the whole burst. |
| 17 | // |
| 18 | // Important: reset does NOT zero the retained head page. Subsequent |
| 19 | // onewayalloc_mallocz() calls may return memory that still holds bytes |
| 20 | // from the previous burst — this matches the mallocz() contract (the "z" |
| 21 | // means "fatal on failure", not "zeroed"). Callers that need zeroed |
| 22 | // memory must use onewayalloc_callocz() just as they would against a |
| 23 | // freshly-created arena; the reset path does not relax that contract. |
| 24 | void onewayalloc_reset(ONEWAYALLOC *owa); |
| 25 | |
| 26 | void *onewayalloc_mallocz(ONEWAYALLOC *owa, size_t size); |
| 27 | void *onewayalloc_callocz(ONEWAYALLOC *owa, size_t nmemb, size_t size); |
| 28 | char *onewayalloc_strdupz(ONEWAYALLOC *owa, const char *s); |
| 29 | void *onewayalloc_memdupz(ONEWAYALLOC *owa, const void *src, size_t size); |
| 30 | void onewayalloc_freez(ONEWAYALLOC *owa, const void *ptr); |
| 31 | |
| 32 | void *onewayalloc_doublesize(ONEWAYALLOC *owa, const void *src, size_t oldsize); |
| 33 | |
| 34 | size_t onewayalloc_allocated_memory(void); |
| 35 | |
| 36 | #endif // ONEWAYALLOC_H |