Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
4e10b08f
Commit
4e10b08f
authored
Jun 22, 2016
by
antirez
Browse files
Modules doc: hint about replacing libc malloc calls.
parent
0b4b7ebd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/modules/TYPES.md
View file @
4e10b08f
...
...
@@ -354,4 +354,18 @@ allocation functions provided by the module API is exactly compatible with
`malloc()`
,
`realloc()`
,
`free()`
and
`strdup()`
, so converting the libraries
in order to use these functions should be trivial.
In case you have an external library that uses libc
`malloc()`
, and you want
to avoid replacing manually all the calls with the Redis Modules API calls,
an approach could be to use simple macros in order to replace the libc calls
with the Redis API calls. Something like this could work:
#define malloc RedisModule_Alloc
#define realloc RedisModule_Realloc
#define free RedisModule_Free
#define strdup RedisModule_Strdup
However take in mind that mixing libc calls with Redis API calls will result
into troubles and crashes, so if you replace calls using macros, you need to
make sure that all the calls are correctly replaced, and that the code with
the substituted calls will never, for example, attempt to call
`RedisModule_Free()`
with a pointer allocated using libc
`malloc()`
.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment