---
title: "Memory Management"
source: https://github.com/obs-rust/obs-studio/blob/524486a44c81ef30b039f10ab955bc778f39e225/docs/sphinx/reference-libobs-util-bmem.rst
commit: 524486a44c81ef30b039f10ab955bc778f39e225
tier: reference
tokens_est: 243
---
# Memory Management

Various functions and helpers used for memory management.

.. code:: cpp

   #include <util/bmem.h>


## Memory Functions


`void *bmalloc(size_t size)`

   Allocates memory and increases the memory leak counter.



`void *brealloc(void *ptr, size_t size)`

   Reallocates memory.  Use only with memory that's been allocated by
   `bmalloc()`.



`void bfree(void *ptr)`

   Frees memory allocated with `bmalloc()`.



`long bnum_allocs(void)`

   Returns current number of active allocations.



`void *bmemdup(const void *ptr, size_t size)`

   Duplicates memory.



`void *bzalloc(size_t size)`

   Inline function that allocates zeroed memory.



`char *bstrdup_n(const char *str, size_t n)`
              wchar_t *bwstrdup_n(const wchar_t *str, size_t n)

   Duplicates a string of *n* bytes and automatically zero-terminates
   it.



`char *bstrdup(const char *str)`
              wchar_t *bwstrdup(const wchar_t *str)

   Duplicates a string.
