diff options
author | Brett Vickers <brett@beevik.com> | 2015-02-26 14:53:07 -0800 |
---|---|---|
committer | Saúl Ibarra Corretgé <saghul@gmail.com> | 2015-03-05 20:02:16 +0100 |
commit | c272f1f1bc0bda625e6441d798c110b4064a6ce2 (patch) | |
tree | b91dda1ab99711d455a3b7beacf0321ecea89555 /docs/src | |
parent | 5645b2d69fe02c9f619e9518085416e8c367fbc0 (diff) | |
download | libuv-c272f1f1bc0bda625e6441d798c110b4064a6ce2.tar.gz libuv-c272f1f1bc0bda625e6441d798c110b4064a6ce2.zip |
memory: add uv_replace_allocator
With uv_replace_allocator, it's possible to override the default
memory allocator's malloc and free calls with functions of the user's
choosing. This allows libuv to interoperate with projects requiring a
custom memory allocator.
Internally, all calls to malloc and free have been replaced with
uv__malloc and uv__free, respectively. The uv__malloc and uv__free
functions call malloc and free unless they have been overridden by a
previous call to uv_replace_allocator.
As part of this change, the special aligned memory allocations
performed in src/win/fs-event.c have been replaced with standard
allocations. The 4-byte alignment being requested in this file was
unnecessary, since standard allocators already guarantee at least an
8-byte alignment.
PR-URL: https://github.com/libuv/libuv/pull/231
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Diffstat (limited to 'docs/src')
-rw-r--r-- | docs/src/misc.rst | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/docs/src/misc.rst b/docs/src/misc.rst index c096fd09..aa3ab6ab 100644 --- a/docs/src/misc.rst +++ b/docs/src/misc.rst @@ -15,6 +15,16 @@ Data types Buffer data type. +.. c:type:: uv_malloc_func + + Function pointer type for the malloc override used by + :c:func:`uv_replace_allocator`. + +.. c:type:: uv_free_func + + Function pointer type for the free override used by + :c:func:`uv_replace_allocator`. + .. c:type:: uv_file Cross platform representation of a file handle. @@ -26,7 +36,7 @@ Data types .. c:type:: uv_os_fd_t Abstract representation of a file descriptor. On Unix systems this is a - `typedef` of `int` and on Windows fa `HANDLE`. + `typedef` of `int` and on Windows a `HANDLE`. .. c:type:: uv_rusage_t @@ -115,6 +125,16 @@ API Returns the libuv version number as a string. For non-release versions "-pre" is appended, so the version number could be "1.2.3-pre". +.. c:function:: int uv_replace_allocator(uv_malloc_func malloc_func, uv_free_func free_func) + + .. versionadded:: 1.5.0 + + Override the use of the standard library's malloc and free functions for + memory allocation. If used, this function must be called before any + other libuv function is called. On success, it returns 0. If called more + than once, the replacement request is ignored and the function returns + ``UV_EINVAL``. + .. c:function:: uv_buf_t uv_buf_init(char* base, unsigned int len) Constructor for :c:type:`uv_buf_t`. |