mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 17:41:05 +00:00
|Fri Mar 24 12:33:27 1995 Mark Lakata (lakata@nsdssp.lbl.gov)
| | * NSZone.c : added #define WORDSIZE sizeof(double) | (NSZoneMalloc): returns machine word aligned pointers. Actually, | the word size is assumed to be equal to or smaller than | sizeof(double). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@207 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
526ca6e886
commit
4702949284
1 changed files with 20 additions and 11 deletions
|
@ -83,6 +83,8 @@
|
||||||
#define ALLOCATED 1
|
#define ALLOCATED 1
|
||||||
#define ZONELINK 2
|
#define ZONELINK 2
|
||||||
|
|
||||||
|
#define WORDSIZE (sizeof(double))
|
||||||
|
|
||||||
typedef struct _chunkdesc
|
typedef struct _chunkdesc
|
||||||
{
|
{
|
||||||
void *base;
|
void *base;
|
||||||
|
@ -291,25 +293,32 @@ void NSMergeZone(NSZone *zonep)
|
||||||
void *NSZoneMalloc(NSZone *zonep, size_t size)
|
void *NSZoneMalloc(NSZone *zonep, size_t size)
|
||||||
{
|
{
|
||||||
int i,pages;
|
int i,pages;
|
||||||
|
size_t newsize,oddsize;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
chunkdesc temp,*chunk;
|
chunkdesc temp,*chunk;
|
||||||
NSZone *newzone;
|
NSZone *newzone;
|
||||||
|
|
||||||
if (zonep == NS_NOZONE) return (*objc_malloc) (size);
|
if (zonep == NS_NOZONE) return (*objc_malloc) (size);
|
||||||
|
/* round size up to the nearest word, so that all chunks are word aligned */
|
||||||
|
oddsize = (size % WORDSIZE);
|
||||||
|
newsize = size - oddsize + (oddsize?WORDSIZE:0);
|
||||||
|
/* if the chunks in this zone can be freed, then we have to scan the whole
|
||||||
|
zone for chunks that have been deallocated for recycling. This requires
|
||||||
|
extra time, so it is not as fast as !canFree */
|
||||||
if (zonep->canFree) {
|
if (zonep->canFree) {
|
||||||
for (i=0;i<zonep->heap.Count;i++) {
|
for (i=0;i<zonep->heap.Count;i++) {
|
||||||
chunk = &(((chunkdesc *)zonep->heap.LList)[i]);
|
chunk = &(((chunkdesc *)zonep->heap.LList)[i]);
|
||||||
|
|
||||||
if (chunk->type == UNUSED) {
|
if (chunk->type == UNUSED) {
|
||||||
if (size <= chunk->size) {
|
if (newsize <= chunk->size) {
|
||||||
ptr = chunk->base;
|
ptr = chunk->base;
|
||||||
chunk->type = ALLOCATED;
|
chunk->type = ALLOCATED;
|
||||||
if (size < chunk->size) {
|
if (newsize < chunk->size) {
|
||||||
temp.base = chunk->base+size;
|
temp.base = chunk->base+newsize;
|
||||||
temp.size = chunk->size-size;
|
temp.size = chunk->size-newsize;
|
||||||
temp.type = UNUSED;
|
temp.type = UNUSED;
|
||||||
addtolist(&temp,&zonep->heap,i+1);
|
addtolist(&temp,&zonep->heap,i+1);
|
||||||
chunk->size = size;
|
chunk->size = newsize;
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +327,7 @@ void *NSZoneMalloc(NSZone *zonep, size_t size)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("following link ...\n");
|
printf("following link ...\n");
|
||||||
#endif
|
#endif
|
||||||
return (NSZoneMalloc((NSZone *)(chunk->base),size));
|
return (NSZoneMalloc((NSZone *)(chunk->base),newsize));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -326,9 +335,9 @@ void *NSZoneMalloc(NSZone *zonep, size_t size)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chunk = &(((chunkdesc *)zonep->heap.LList)[0]);
|
chunk = &(((chunkdesc *)zonep->heap.LList)[0]);
|
||||||
if (chunk->size > size) {
|
if (chunk->size > newsize) {
|
||||||
ptr = chunk->base;
|
ptr = chunk->base;
|
||||||
chunk->size -=size;
|
chunk->size -=newsize;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
if (zonep->heap.Count == 2) {
|
if (zonep->heap.Count == 2) {
|
||||||
|
@ -337,7 +346,7 @@ void *NSZoneMalloc(NSZone *zonep, size_t size)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("following link ...\n");
|
printf("following link ...\n");
|
||||||
#endif
|
#endif
|
||||||
return (NSZoneMalloc((NSZone *)(chunk->base),size));
|
return (NSZoneMalloc((NSZone *)(chunk->base),newsize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,7 +354,7 @@ void *NSZoneMalloc(NSZone *zonep, size_t size)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("*** no more memory in zone, creating link to new zone\n");
|
printf("*** no more memory in zone, creating link to new zone\n");
|
||||||
#endif
|
#endif
|
||||||
pages = size/(zonep->granularity)+1;
|
pages = newsize/(zonep->granularity)+1;
|
||||||
newzone = NSCreateZone(pages*(zonep->granularity),
|
newzone = NSCreateZone(pages*(zonep->granularity),
|
||||||
zonep->granularity,zonep->canFree);
|
zonep->granularity,zonep->canFree);
|
||||||
if (newzone == NS_NOZONE) {
|
if (newzone == NS_NOZONE) {
|
||||||
|
@ -359,7 +368,7 @@ void *NSZoneMalloc(NSZone *zonep, size_t size)
|
||||||
temp.size = 0;
|
temp.size = 0;
|
||||||
temp.type = ZONELINK;
|
temp.type = ZONELINK;
|
||||||
addtolist(&temp,&zonep->heap,zonep->heap.Count);
|
addtolist(&temp,&zonep->heap,zonep->heap.Count);
|
||||||
return (NSZoneMalloc(newzone,size));
|
return (NSZoneMalloc(newzone,newsize));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue