|
From: blackh <gra...@li...> - 2003-06-05 12:28:26
|
blackh Thu Jun 5 05:28:25 2003 EDT
Modified files:
/grapevine/cpp Allocator.h
Log:
This should fix the memory leak I just introduced, but I haven't tested
it yet.
Index: grapevine/cpp/Allocator.h
diff -u grapevine/cpp/Allocator.h:1.1 grapevine/cpp/Allocator.h:1.2
--- grapevine/cpp/Allocator.h:1.1 Thu Jun 5 04:45:08 2003
+++ grapevine/cpp/Allocator.h Thu Jun 5 05:28:24 2003
@@ -1,4 +1,4 @@
-// $Id: Allocator.h,v 1.1 2003/06/05 11:45:08 blackh Exp $
+// $Id: Allocator.h,v 1.2 2003/06/05 12:28:24 blackh Exp $
#ifndef _ALLOCATOR_H_
#define _ALLOCATOR_H_
@@ -32,17 +32,17 @@
* since most of our blocks are tiny.
*/
-#define GRAPEVINE_BLOCKSIZES 32*sizeof(void*) /* The number of different block sizes */
+#define GRAPEVINE_BLOCKSIZES 32 /* The number of different block sizes */
#define GRAPEVINE_ATONCE 32 /* Allocate this many blocks at once */
extern void* grapevineFreeLists[GRAPEVINE_BLOCKSIZES];
inline void* grapevineAllocateSmall(size_t size)
{
- size = (size + (sizeof(void*)-1)) & ~(sizeof(void*)-1);
- assert(size >= sizeof(void*));
- assert(size < GRAPEVINE_BLOCKSIZES);
- void*& freeList = grapevineFreeLists[size];
+ int idx = (size + (sizeof(void*)-1)) / sizeof(void*);
+ assert(idx >= 1);
+ assert(idx < GRAPEVINE_BLOCKSIZES);
+ void*& freeList = grapevineFreeLists[idx];
if (freeList == NULL) {
char* buf = new char[size*GRAPEVINE_ATONCE];
void* p = NULL;
@@ -60,10 +60,10 @@
inline void grapevineFreeSmall(void* p, size_t size)
{
- size = (size + (sizeof(void*)-1)) & ~(sizeof(void*)-1);
- assert(size >= sizeof(void*));
- assert(size < GRAPEVINE_BLOCKSIZES);
- void*& freeList = grapevineFreeLists[size];
+ int idx = (size + (sizeof(void*)-1)) / sizeof(void*);
+ assert(idx >= 1);
+ assert(idx < GRAPEVINE_BLOCKSIZES);
+ void*& freeList = grapevineFreeLists[idx];
*((void**)p) = freeList;
freeList = p;
@@ -71,7 +71,7 @@
inline void* grapevineAllocateBig(size_t size)
{
- if (size < GRAPEVINE_BLOCKSIZES)
+ if (size <= (GRAPEVINE_BLOCKSIZES-1)*sizeof(void*))
return grapevineAllocateSmall(size);
else
return malloc(size);
@@ -79,7 +79,7 @@
inline void grapevineFreeBig(void* p, size_t size)
{
- if (size < GRAPEVINE_BLOCKSIZES)
+ if (size <= (GRAPEVINE_BLOCKSIZES-1)*sizeof(void*))
return grapevineFreeSmall(p, size);
else
return free(p);
@@ -106,9 +106,9 @@
void deallocate(void* p, size_type n)
{
- grapevineFreeBig(p, n);
+ grapevineFreeBig(p, n * sizeof(T));
}
-
+
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }
grapevine_allocator<T>& operator=(const grapevine_allocator&) { return *this; }
|