home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1988-1996 NeXT Software, Inc.
-
- #ifndef _OBJC_ZONE_H_
- #define _OBJC_ZONE_H_
-
- #import <stddef.h>
- #import <objc/objc-api.h> // for OBJC_EXPORT
-
- #ifdef WIN32
- #if !defined(_USE_PDO_MALLOC)
- #define _USE_PDO_MALLOC
- #include <malloc.h>
- /* Normally this won't matter since we use the system's free. The only
- case where it become imperitive that this is used is for memory that
- was vm_allocate'ed and then later NXAddRegion'ed. In this case,
- we need to track that memory so that vm_deallocate is called on it
- instead of free. */
- #define free(ptr) pdo_free(ptr)
- #define malloc(size) pdo_malloc(size)
- #define realloc(ptr,size) pdo_realloc(ptr,size)
- #define calloc(num,size) pdo_calloc(num,size)
- #endif /* !defined(_USE_PDO_MALLOC) */
- #endif /* WIN32 */
-
- /*
- * Interface to zone based malloc.
- */
-
- typedef struct _NXZone {
- void *(*realloc)(struct _NXZone *zonep, void *ptr, size_t size);
- void *(*malloc)(struct _NXZone *zonep, size_t size);
- void (*free)(struct _NXZone *zonep, void *ptr);
- void (*destroy)(struct _NXZone *zonep);
- /* Implementation specific entries */
- /* Do not depend on the size of this structure */
- } NXZone;
-
- #define NX_NOZONE ((NXZone *)0)
-
- /*
- * Returns the default zone used by the malloc(3) calls.
- */
- OBJC_EXPORT NXZone *NXDefaultMallocZone(void);
-
- /*
- * Create a new zone with its own memory pool.
- * If canfree is 0 the allocator will never free memory and mallocing will be fast
- */
- OBJC_EXPORT NXZone *NXCreateZone(size_t startSize, size_t granularity, int canFree);
-
- /*
- * Create a new zone who obtains memory from another zone.
- * Returns NX_NOZONE if the passed zone is already a child.
- */
- OBJC_EXPORT NXZone *NXCreateChildZone(NXZone *parentZone, size_t startSize, size_t granularity, int canFree);
-
- /*
- * The zone is destroyed and all memory reclaimed.
- */
- #define NXDestroyZone(zonep) \
- ((*(zonep)->destroy)(zonep))
-
- /*
- * Will merge zone with the parent zone. Malloced areas are still valid.
- * Must be an child zone.
- */
- OBJC_EXPORT void NXMergeZone(NXZone *zonep);
-
- #define NXZoneMalloc(zonep, size) \
- ((*(zonep)->malloc)(zonep, size))
-
- #define NXZoneRealloc(zonep, ptr, size) \
- ((*(zonep)->realloc)(zonep, ptr, size))
-
- #define NXZoneFree(zonep, ptr) \
- ((*(zonep)->free)(zonep, ptr))
-
- /*
- * Calls NXZoneMalloc and then bzero.
- */
- OBJC_EXPORT void *NXZoneCalloc(NXZone *zonep, size_t numElems, size_t byteSize);
-
- /*
- * Returns the zone for a pointer.
- * NX_NOZONE if not in any zone.
- * The ptr must have been returned from a malloc or realloc call.
- */
- OBJC_EXPORT NXZone *NXZoneFromPtr(void *ptr);
-
- /*
- * Debugging Helpers.
- */
-
- /*
- * Will print to stdout if this pointer is in the malloc heap, free status, and size.
- */
- OBJC_EXPORT void NXZonePtrInfo(void *ptr);
-
- /*
- * Will verify all internal malloc information.
- * This is what malloc_debug calls.
- */
- #if !defined(WIN32)
- OBJC_EXPORT int NXMallocCheck(void);
- #endif
-
- /*
- * Give a zone a name.
- *
- * The string will be copied.
- */
- OBJC_EXPORT void NXNameZone(NXZone *z, const char *name);
-
- /*
- * Prototypes
- */
-
- #if !defined(__MACH__)
- OBJC_EXPORT void *pdo_malloc (size_t size);
- OBJC_EXPORT void *pdo_realloc (void *ptr, size_t size);
- OBJC_EXPORT void *pdo_calloc (size_t num, size_t size);
- OBJC_EXPORT void pdo_free (void* ptr);
- #endif
-
- #endif /* _OBJC_ZONE_H_ */
-