2002-12-31 19:31:46 +00:00
|
|
|
/** Zone memory management. -*- Mode: ObjC -*-
|
1999-09-28 10:25:42 +00:00
|
|
|
Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
|
1995-07-01 19:01:11 +00:00
|
|
|
|
1997-05-03 18:15:44 +00:00
|
|
|
Written by: Yoo C. Chung <wacko@laplace.snu.ac.kr>
|
1997-03-03 19:43:25 +00:00
|
|
|
Date: January 1997
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-23 03:40:21 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
1997-03-03 19:43:25 +00:00
|
|
|
|
1995-03-23 03:40:21 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
1997-03-03 19:43:25 +00:00
|
|
|
|
1995-03-23 03:40:21 +00:00
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
2005-05-22 03:32:16 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
2002-12-31 19:31:46 +00:00
|
|
|
|
|
|
|
AutogsdocSource: NSZone.m
|
|
|
|
AutogsdocSource: NSPage.m
|
|
|
|
|
|
|
|
*/
|
1995-03-23 03:40:21 +00:00
|
|
|
|
1997-01-06 21:35:52 +00:00
|
|
|
#ifndef __NSZone_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
#define __NSZone_h_GNUSTEP_BASE_INCLUDE
|
1995-03-23 03:40:21 +00:00
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Primary structure representing an <code>NSZone</code>. Technically it
|
|
|
|
* consists of a set of function pointers for zone upkeep functions plus some
|
|
|
|
* other things-
|
|
|
|
<example>
|
|
|
|
{
|
|
|
|
// Functions for zone.
|
|
|
|
void *(*malloc)(struct _NSZone *zone, size_t size);
|
|
|
|
void *(*realloc)(struct _NSZone *zone, void *ptr, size_t size);
|
|
|
|
void (*free)(struct _NSZone *zone, void *ptr);
|
|
|
|
void (*recycle)(struct _NSZone *zone);
|
|
|
|
BOOL (*check)(struct _NSZone *zone);
|
|
|
|
BOOL (*lookup)(struct _NSZone *zone, void *ptr);
|
|
|
|
|
|
|
|
// Zone statistics (not always maintained).
|
|
|
|
struct NSZoneStats (*stats)(struct _NSZone *zone);
|
|
|
|
|
|
|
|
size_t gran; // Zone granularity (passed in on initialization)
|
|
|
|
NSString *name; // Name of zone (default is 'nil')
|
|
|
|
NSZone *next; // Pointer used for internal management of multiple zones.
|
|
|
|
}</example>
|
|
|
|
*/
|
2000-10-31 16:17:33 +00:00
|
|
|
typedef struct _NSZone NSZone;
|
|
|
|
|
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
1996-10-31 17:22:04 +00:00
|
|
|
|
1997-01-06 21:35:52 +00:00
|
|
|
@class NSString;
|
1996-05-28 20:47:33 +00:00
|
|
|
|
1997-01-06 21:35:52 +00:00
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* <code>NSZoneStats</code> is the structure returned by the NSZoneStats()
|
|
|
|
* function that summarizes the current usage of a zone. It is similar to
|
|
|
|
* the structure <em>mstats</em> in the GNU C library. It has 5 fields of
|
|
|
|
* type <code>size_t</code>-
|
|
|
|
* <deflist>
|
|
|
|
* <term><code>bytes_total</code></term>
|
|
|
|
* <desc>This is the total size of memory managed by the zone, in bytes.</desc>
|
|
|
|
* <term><code>chunks_used</code></term>
|
|
|
|
* <desc>This is the number of memory chunks in use in the zone.</desc>
|
|
|
|
* <term><code>bytes_used</code></term>
|
|
|
|
* <desc>This is the number of bytes in use.</desc>
|
|
|
|
* <term><code>chunks_free</code></term>
|
|
|
|
* <desc>This is the number of memory chunks that are not in use.</desc>
|
|
|
|
* <term><code>bytes_free</code></term>
|
|
|
|
* <desc>This is the number of bytes managed by the zone that are not in use.</desc>
|
|
|
|
* </deflist>
|
|
|
|
*/
|
1997-03-03 19:58:17 +00:00
|
|
|
struct NSZoneStats
|
|
|
|
{
|
|
|
|
size_t bytes_total;
|
|
|
|
size_t chunks_used;
|
|
|
|
size_t bytes_used;
|
|
|
|
size_t chunks_free;
|
|
|
|
size_t bytes_free;
|
|
|
|
};
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Primary structure representing an <code>NSZone</code>. Technically it
|
|
|
|
* consists of a set of function pointers for zone upkeep functions plus some
|
|
|
|
* other things-
|
|
|
|
<example>
|
|
|
|
{
|
|
|
|
// Functions for zone.
|
|
|
|
void *(*malloc)(struct _NSZone *zone, size_t size);
|
|
|
|
void *(*realloc)(struct _NSZone *zone, void *ptr, size_t size);
|
|
|
|
void (*free)(struct _NSZone *zone, void *ptr);
|
|
|
|
void (*recycle)(struct _NSZone *zone);
|
|
|
|
BOOL (*check)(struct _NSZone *zone);
|
|
|
|
BOOL (*lookup)(struct _NSZone *zone, void *ptr);
|
|
|
|
|
|
|
|
// Zone statistics (not always maintained).
|
|
|
|
struct NSZoneStats (*stats)(struct _NSZone *zone);
|
|
|
|
|
|
|
|
size_t gran; // Zone granularity (passed in on initialization)
|
|
|
|
NSString *name; // Name of zone (default is 'nil')
|
|
|
|
NSZone *next; // Pointer used for internal management of multiple zones.
|
|
|
|
}</example>
|
|
|
|
*/
|
1997-01-06 21:35:52 +00:00
|
|
|
struct _NSZone
|
|
|
|
{
|
1997-03-03 19:43:25 +00:00
|
|
|
/* Functions for zone. */
|
|
|
|
void *(*malloc)(struct _NSZone *zone, size_t size);
|
|
|
|
void *(*realloc)(struct _NSZone *zone, void *ptr, size_t size);
|
|
|
|
void (*free)(struct _NSZone *zone, void *ptr);
|
|
|
|
void (*recycle)(struct _NSZone *zone);
|
1997-03-03 19:58:17 +00:00
|
|
|
BOOL (*check)(struct _NSZone *zone);
|
1998-10-15 05:03:16 +00:00
|
|
|
BOOL (*lookup)(struct _NSZone *zone, void *ptr);
|
1997-03-03 19:58:17 +00:00
|
|
|
struct NSZoneStats (*stats)(struct _NSZone *zone);
|
|
|
|
|
1997-03-03 19:43:25 +00:00
|
|
|
size_t gran; // Zone granularity
|
|
|
|
NSString *name; // Name of zone (default is 'nil')
|
1998-10-15 05:03:16 +00:00
|
|
|
NSZone *next;
|
1997-01-06 21:35:52 +00:00
|
|
|
};
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Try to get more memory - the normal process has failed.
|
|
|
|
* If we can't do anything, just return a null pointer.
|
|
|
|
* Try to do some logging if possible.
|
|
|
|
*/
|
1999-01-28 17:21:03 +00:00
|
|
|
void *GSOutOfMemory(size_t size, BOOL retry);
|
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
#ifdef IN_NSZONE_M
|
|
|
|
#define GS_ZONE_SCOPE extern
|
|
|
|
#define GS_ZONE_ATTR
|
|
|
|
#else
|
|
|
|
#define GS_ZONE_SCOPE static inline
|
|
|
|
#define GS_ZONE_ATTR __attribute__((unused))
|
|
|
|
#endif
|
|
|
|
|
1999-04-12 12:53:30 +00:00
|
|
|
/* Default zone. Name is hopelessly long so that no one will ever
|
|
|
|
want to use it. ;) Private variable. */
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT NSZone* __nszone_private_hidden_default_zone;
|
1999-04-12 12:53:30 +00:00
|
|
|
|
1999-01-28 17:21:03 +00:00
|
|
|
#ifndef GS_WITH_GC
|
|
|
|
#define GS_WITH_GC 0
|
|
|
|
#endif
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
|
|
|
#include <gc.h>
|
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT NSZone* __nszone_private_hidden_atomic_zone;
|
1999-09-28 10:25:42 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
1999-04-12 12:53:30 +00:00
|
|
|
{ return __nszone_private_hidden_default_zone; }
|
1999-01-28 17:21:03 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* NSDefaultMallocZone (void)
|
1999-04-12 12:53:30 +00:00
|
|
|
{ return __nszone_private_hidden_default_zone; }
|
1999-01-28 17:21:03 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* GSAtomicMallocZone (void)
|
1999-09-28 19:35:09 +00:00
|
|
|
{ return __nszone_private_hidden_atomic_zone; }
|
1999-09-28 10:25:42 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* NSZoneFromPointer (void *ptr)
|
1999-04-12 12:53:30 +00:00
|
|
|
{ return __nszone_private_hidden_default_zone; }
|
1999-01-28 17:21:03 +00:00
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Allocates and returns memory for elems items of size bytes, in the
|
|
|
|
* given zone. Returns NULL if allocation of size 0 requested. Raises
|
|
|
|
* <code>NSMallocException</code> if not enough free memory in zone to
|
|
|
|
* allocate and no more can be obtained from system, unless using the
|
|
|
|
* default zone, in which case NULL is returned.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneMalloc (NSZone *zone, size_t size)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
1999-09-28 10:25:42 +00:00
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
if (zone == GSAtomicMallocZone())
|
1999-09-28 19:35:09 +00:00
|
|
|
ptr = (void*)GC_MALLOC_ATOMIC(size);
|
1999-09-28 10:25:42 +00:00
|
|
|
else
|
1999-09-28 19:35:09 +00:00
|
|
|
ptr = (void*)GC_MALLOC(size);
|
1999-01-28 17:21:03 +00:00
|
|
|
|
|
|
|
if (ptr == 0)
|
|
|
|
ptr = GSOutOfMemory(size, YES);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Allocates and returns cleared memory for elems items of size bytes, in the
|
|
|
|
* given zone. Returns NULL if allocation of size 0 requested. Raises
|
|
|
|
* <code>NSMallocException</code> if not enough free memory in zone to
|
|
|
|
* allocate and no more can be obtained from system, unless using the
|
|
|
|
* default zone, in which case NULL is returned.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneCalloc (NSZone *zone, size_t elems, size_t bytes)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
size_t size = elems * bytes;
|
1999-09-28 10:25:42 +00:00
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
if (zone == __nszone_private_hidden_atomic_zone)
|
1999-09-28 19:35:09 +00:00
|
|
|
ptr = (void*)GC_MALLOC_ATOMIC(size);
|
1999-09-28 10:25:42 +00:00
|
|
|
else
|
1999-09-28 19:35:09 +00:00
|
|
|
ptr = (void*)GC_MALLOC(size);
|
1999-01-28 17:21:03 +00:00
|
|
|
|
|
|
|
if (ptr == 0)
|
1999-09-28 19:35:09 +00:00
|
|
|
ptr = GSOutOfMemory(size, NO);
|
1999-01-28 17:21:03 +00:00
|
|
|
memset(ptr, '\0', size);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneRealloc (NSZone *zone, void *ptr, size_t size)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
ptr = GC_REALLOC(ptr, size);
|
|
|
|
if (ptr == 0)
|
|
|
|
GSOutOfMemory(size, NO);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void NSRecycleZone (NSZone *zone)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void NSZoneFree (NSZone *zone, void *ptr)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
GC_FREE(ptr);
|
|
|
|
}
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Sets name of the given zone (useful for debugging and logging).
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void NSSetZoneName (NSZone *zone, NSString *name)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Sets name of the given zone (useful for debugging and logging).
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSString* NSZoneName (NSZone *zone)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
1999-05-21 15:21:41 +00:00
|
|
|
#ifndef NO_GNUSTEP
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Allocates mmemory of size bytes from zone, with the assumption that the
|
|
|
|
* memory will never contain pointers. This is only relevant in situations
|
|
|
|
* where a form of garbage collection is enabled, and NSZoneMalloc() should
|
|
|
|
* always be used otherwise. Not defined by OpenStep or OS X.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneMallocAtomic (NSZone *zone, size_t size)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
1999-09-28 19:35:09 +00:00
|
|
|
return NSZoneMalloc(GSAtomicMallocZone(), size);
|
1999-05-21 15:21:41 +00:00
|
|
|
}
|
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE BOOL NSZoneCheck (NSZone *zone)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE struct NSZoneStats NSZoneStats (NSZone *zone)
|
1999-01-28 17:21:03 +00:00
|
|
|
{
|
|
|
|
struct NSZoneStats stats = { 0 };
|
|
|
|
return stats;
|
|
|
|
}
|
1999-05-21 15:21:41 +00:00
|
|
|
#endif
|
1999-01-28 17:21:03 +00:00
|
|
|
|
|
|
|
#else /* GS_WITH_GC */
|
1996-03-22 02:35:21 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT NSZone* NSCreateZone (size_t start, size_t gran, BOOL canFree);
|
1995-03-23 03:40:21 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* NSDefaultMallocZone (void) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Returns the default zone used for memory allocation, created at startup.
|
|
|
|
* This zone cannot be recycled.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* NSDefaultMallocZone (void)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
return __nszone_private_hidden_default_zone;
|
|
|
|
}
|
1995-03-23 03:40:21 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* GSAtomicMallocZone (void) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Returns the default zone used for atomic memory allocation (see
|
|
|
|
* NSMallocAtomic()), if no zone is specified.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSZone* GSAtomicMallocZone (void)
|
1999-09-28 10:25:42 +00:00
|
|
|
{
|
|
|
|
return NSDefaultMallocZone();
|
|
|
|
}
|
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT NSZone* NSZoneFromPointer (void *ptr);
|
1995-03-23 03:40:21 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneMalloc (NSZone *zone, size_t size) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Allocates and returns cleared memory for elems items of size bytes, in the
|
|
|
|
* given zone. Returns NULL if allocation of size 0 requested. Raises
|
|
|
|
* <code>NSMallocException</code> if not enough free memory in zone to
|
|
|
|
* allocate and no more can be obtained from system, unless using the
|
|
|
|
* default zone, in which case NULL is returned.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneMalloc (NSZone *zone, size_t size)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
return (zone->malloc)(zone, size);
|
|
|
|
}
|
1996-03-22 02:35:21 +00:00
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Allocates and returns cleared memory for elems items of size bytes, in the
|
|
|
|
* given zone. Returns NULL if allocation of size 0 requested. Raises
|
|
|
|
* <code>NSMallocException</code> if not enough free memory in zone to
|
|
|
|
* allocate and no more can be obtained from system, unless using the
|
|
|
|
* default zone, in which case NULL is returned.
|
|
|
|
*/
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT void* NSZoneCalloc (NSZone *zone, size_t elems, size_t bytes);
|
1996-05-28 20:47:33 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void*
|
|
|
|
NSZoneRealloc (NSZone *zone, void *ptr, size_t size) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Reallocates the chunk of memory in zone pointed to by ptr to a new one of
|
|
|
|
* size bytes. Existing contents in ptr are copied over. Raises an
|
|
|
|
* <code>NSMallocException</code> if insufficient memory is available in the
|
|
|
|
* zone and no more memory can be obtained from the system, unless using the
|
|
|
|
* default zone, in which case NULL is returned.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneRealloc (NSZone *zone, void *ptr, size_t size)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
return (zone->realloc)(zone, ptr, size);
|
|
|
|
}
|
1997-01-06 21:35:52 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void NSRecycleZone (NSZone *zone) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Return memory for an entire zone to system. In fact, this will not be done
|
|
|
|
* unless all memory in the zone has been explicitly freed (by calls to
|
|
|
|
* ZNSZoneFree()). For "non-freeable" zones, the number of NSZoneFree() calls
|
|
|
|
* must simply equal the number of allocation calls. The default zone, on the
|
|
|
|
* other hand, cannot be recycled.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void NSRecycleZone (NSZone *zone)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
(zone->recycle)(zone);
|
|
|
|
}
|
1997-01-06 21:35:52 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void NSZoneFree (NSZone *zone, void *ptr) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Frees memory pointed to by ptr (which should have been allocated by a
|
|
|
|
* previous call to NSZoneMalloc(), NSZoneCalloc(), or NSZoneRealloc()) and
|
|
|
|
* returns it to zone. Note, if this is a nonfreeable zone, the memory is
|
|
|
|
* not actually freed, but the count of number of free()s is updated.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void NSZoneFree (NSZone *zone, void *ptr)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
(zone->free)(zone, ptr);
|
|
|
|
}
|
1996-05-28 20:47:33 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT void NSSetZoneName (NSZone *zone, NSString *name);
|
1996-05-28 20:47:33 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSString* NSZoneName (NSZone *zone) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Returns the name assigned to the zone, if one has been given (see
|
|
|
|
* NSSetZoneName()), otherwise nil. Useful for debugging/logging.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE NSString* NSZoneName (NSZone *zone)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
return zone->name;
|
|
|
|
}
|
1996-05-28 20:47:33 +00:00
|
|
|
|
1999-05-21 15:21:41 +00:00
|
|
|
#ifndef NO_GNUSTEP
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void*
|
|
|
|
NSZoneMallocAtomic (NSZone *zone, size_t size) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Allocates memory of size bytes from zone, with the assumption that the
|
|
|
|
* memory will never contain pointers. This is only relevant in situations
|
|
|
|
* where a form of garbage collection is enabled, and NSZoneMalloc() should
|
|
|
|
* always be used otherwise. Not defined by OpenStep or OS X.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE void* NSZoneMallocAtomic (NSZone *zone, size_t size)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
return (zone->malloc)(zone, size);
|
|
|
|
}
|
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE BOOL NSZoneCheck (NSZone *zone) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Checks integrity of a zone. Not defined by OpenStep or OS X.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE BOOL NSZoneCheck (NSZone *zone)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
return (zone->check)(zone);
|
|
|
|
}
|
1997-03-03 19:58:17 +00:00
|
|
|
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE struct NSZoneStats NSZoneStats (NSZone *zone) GS_ZONE_ATTR;
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Obtain statistics about the zone. Implementation emphasis is on
|
|
|
|
* correctness, not speed. Not defined by OpenStep or OS X.
|
|
|
|
*/
|
2000-06-22 03:15:27 +00:00
|
|
|
GS_ZONE_SCOPE struct NSZoneStats NSZoneStats (NSZone *zone)
|
1999-05-21 15:21:41 +00:00
|
|
|
{
|
|
|
|
if (!zone)
|
|
|
|
zone = NSDefaultMallocZone();
|
|
|
|
return (zone->stats)(zone);
|
|
|
|
}
|
|
|
|
#endif /* NO_GNUSTEP */
|
1997-03-03 19:58:17 +00:00
|
|
|
|
1999-01-28 17:21:03 +00:00
|
|
|
#endif /* GS_WITH_GC */
|
|
|
|
|
1999-11-18 15:18:47 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT unsigned NSPageSize (void) __attribute__ ((const));
|
1999-11-18 15:18:47 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT unsigned NSLogPageSize (void) __attribute__ ((const));
|
1999-11-18 15:18:47 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT unsigned NSRoundDownToMultipleOfPageSize (unsigned bytes)
|
1999-11-18 15:18:47 +00:00
|
|
|
__attribute__ ((const));
|
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT unsigned NSRoundUpToMultipleOfPageSize (unsigned bytes)
|
1999-11-18 15:18:47 +00:00
|
|
|
__attribute__ ((const));
|
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT unsigned NSRealMemoryAvailable (void);
|
1999-11-18 15:18:47 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT void* NSAllocateMemoryPages (unsigned bytes);
|
1999-11-18 15:18:47 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT void NSDeallocateMemoryPages (void *ptr, unsigned bytes);
|
1999-11-18 15:18:47 +00:00
|
|
|
|
2000-06-14 04:03:56 +00:00
|
|
|
GS_EXPORT void NSCopyMemoryPages (const void *src, void *dest, unsigned bytes);
|
1999-11-18 15:18:47 +00:00
|
|
|
|
1997-03-03 19:43:25 +00:00
|
|
|
#endif /* not __NSZone_h_GNUSTEP_BASE_INCLUDE */
|