Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d8b5f18f
Commit
d8b5f18f
authored
Oct 27, 2009
by
antirez
Browse files
zmalloc Solaris fixes thanks to Alan Harder
parent
6e333bbe
Changes
1
Hide whitespace changes
Inline
Side-by-side
zmalloc.c
View file @
d8b5f18f
...
@@ -33,6 +33,12 @@
...
@@ -33,6 +33,12 @@
#include <string.h>
#include <string.h>
#include "config.h"
#include "config.h"
#if defined(__sun)
#define PREFIX_SIZE sizeof(long long)
#else
#define PREFIX_SIZE sizeof(size_t)
#endif
static
size_t
used_memory
=
0
;
static
size_t
used_memory
=
0
;
static
void
zmalloc_oom
(
size_t
size
)
{
static
void
zmalloc_oom
(
size_t
size
)
{
...
@@ -43,7 +49,7 @@ static void zmalloc_oom(size_t size) {
...
@@ -43,7 +49,7 @@ static void zmalloc_oom(size_t size) {
}
}
void
*
zmalloc
(
size_t
size
)
{
void
*
zmalloc
(
size_t
size
)
{
void
*
ptr
=
malloc
(
size
+
sizeof
(
size_t
)
);
void
*
ptr
=
malloc
(
size
+
PREFIX_SIZE
);
if
(
!
ptr
)
zmalloc_oom
(
size
);
if
(
!
ptr
)
zmalloc_oom
(
size
);
#ifdef HAVE_MALLOC_SIZE
#ifdef HAVE_MALLOC_SIZE
...
@@ -51,8 +57,8 @@ void *zmalloc(size_t size) {
...
@@ -51,8 +57,8 @@ void *zmalloc(size_t size) {
return
ptr
;
return
ptr
;
#else
#else
*
((
size_t
*
)
ptr
)
=
size
;
*
((
size_t
*
)
ptr
)
=
size
;
used_memory
+=
size
+
sizeof
(
size_t
)
;
used_memory
+=
size
+
PREFIX_SIZE
;
return
(
char
*
)
ptr
+
sizeof
(
size_t
)
;
return
(
char
*
)
ptr
+
PREFIX_SIZE
;
#endif
#endif
}
}
...
@@ -73,15 +79,15 @@ void *zrealloc(void *ptr, size_t size) {
...
@@ -73,15 +79,15 @@ void *zrealloc(void *ptr, size_t size) {
used_memory
+=
redis_malloc_size
(
newptr
);
used_memory
+=
redis_malloc_size
(
newptr
);
return
newptr
;
return
newptr
;
#else
#else
realptr
=
(
char
*
)
ptr
-
sizeof
(
size_t
)
;
realptr
=
(
char
*
)
ptr
-
PREFIX_SIZE
;
oldsize
=
*
((
size_t
*
)
realptr
);
oldsize
=
*
((
size_t
*
)
realptr
);
newptr
=
realloc
(
realptr
,
size
+
sizeof
(
size_t
)
);
newptr
=
realloc
(
realptr
,
size
+
PREFIX_SIZE
);
if
(
!
newptr
)
zmalloc_oom
(
size
);
if
(
!
newptr
)
zmalloc_oom
(
size
);
*
((
size_t
*
)
newptr
)
=
size
;
*
((
size_t
*
)
newptr
)
=
size
;
used_memory
-=
oldsize
;
used_memory
-=
oldsize
;
used_memory
+=
size
;
used_memory
+=
size
;
return
(
char
*
)
newptr
+
sizeof
(
size_t
)
;
return
(
char
*
)
newptr
+
PREFIX_SIZE
;
#endif
#endif
}
}
...
@@ -96,9 +102,9 @@ void zfree(void *ptr) {
...
@@ -96,9 +102,9 @@ void zfree(void *ptr) {
used_memory
-=
redis_malloc_size
(
ptr
);
used_memory
-=
redis_malloc_size
(
ptr
);
free
(
ptr
);
free
(
ptr
);
#else
#else
realptr
=
(
char
*
)
ptr
-
sizeof
(
size_t
)
;
realptr
=
(
char
*
)
ptr
-
PREFIX_SIZE
;
oldsize
=
*
((
size_t
*
)
realptr
);
oldsize
=
*
((
size_t
*
)
realptr
);
used_memory
-=
oldsize
+
sizeof
(
size_t
)
;
used_memory
-=
oldsize
+
PREFIX_SIZE
;
free
(
realptr
);
free
(
realptr
);
#endif
#endif
}
}
...
...
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