vmalloc.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #pragma once
  11. #include <stddef.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* Public header file for the virtual malloc package.
  16. **
  17. ** Written by Kiem-Phong Vo, [email protected], 01/16/94.
  18. */
  19. typedef struct _vmalloc_s Vmalloc_t;
  20. struct _vmalloc_s {
  21. void **allocated; /* pointers we have given out */
  22. size_t size; /* used entries in `allocated` */
  23. size_t capacity; /* available entries in `allocated` */
  24. };
  25. extern Vmalloc_t *vmopen(void);
  26. extern void vmclose(Vmalloc_t*);
  27. extern void vmclear(Vmalloc_t*);
  28. /** allocate heap memory
  29. *
  30. * @param vm region allocating from
  31. * @param size desired block size
  32. * @returns Memory fulfilling the allocation request or NULL on failure
  33. */
  34. void *vmalloc(Vmalloc_t *vm, size_t size);
  35. /** free heap memory
  36. *
  37. * @param vm Region the pointer was originally allocated from
  38. * @param data The pointer originally received from vmalloc
  39. */
  40. void vmfree(Vmalloc_t *vm, void *data);
  41. extern char *vmstrdup(Vmalloc_t *, const char *);
  42. #ifdef __cplusplus
  43. }
  44. #endif