1 /* Copyright (C) 2001-2012 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, 8 modified or distributed except as expressly authorized under the terms 9 of the license contained in the file LICENSE in this distribution. 10 11 Refer to licensing information at http://www.artifex.com or contact 12 Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael, 13 CA 94903, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Memory allocator extensions for standard allocator */ 18 19 #ifndef gsalloc_INCLUDED 20 # define gsalloc_INCLUDED 21 22 /* The following should not be needed at this level! */ 23 24 #ifndef gs_ref_memory_DEFINED 25 # define gs_ref_memory_DEFINED 26 typedef struct gs_ref_memory_s gs_ref_memory_t; 27 #endif 28 29 /* 30 * Define a structure and interface for GC-related allocator state. 31 */ 32 typedef struct gs_memory_gc_status_s { 33 /* Set by client */ 34 long vm_threshold; /* GC interval */ 35 long max_vm; /* maximum allowed allocation */ 36 int *psignal; /* if not NULL, store signal_value */ 37 /* here if we go over the vm_threshold */ 38 int signal_value; /* value to store in *psignal */ 39 bool enabled; /* auto GC enabled if true */ 40 /* Set by allocator */ 41 long requested; /* amount of last failing request */ 42 } gs_memory_gc_status_t; 43 void gs_memory_gc_status(const gs_ref_memory_t *, gs_memory_gc_status_t *); 44 void gs_memory_set_gc_status(gs_ref_memory_t *, const gs_memory_gc_status_t *); 45 void gs_memory_set_vm_threshold(gs_ref_memory_t * mem, long val); 46 void gs_memory_set_vm_reclaim(gs_ref_memory_t * mem, bool enabled); 47 48 /* ------ Initialization ------ */ 49 50 /* 51 * Allocate and mostly initialize the state of an allocator (system, global, 52 * or local). Does not initialize global or space. 53 */ 54 gs_ref_memory_t *ialloc_alloc_state(gs_memory_t *, uint); 55 56 /* 57 * Add a chunk to an externally controlled allocator. Such allocators 58 * allocate all objects as immovable, are not garbage-collected, and 59 * don't attempt to acquire additional memory (or free chunks) on their own. 60 */ 61 int ialloc_add_chunk(gs_ref_memory_t *, ulong, client_name_t); 62 63 /* ------ Internal routines ------ */ 64 65 /* Prepare for a GC. */ 66 void ialloc_gc_prepare(gs_ref_memory_t *); 67 68 /* Initialize after a save. */ 69 void ialloc_reset(gs_ref_memory_t *); 70 71 /* Initialize after a save or GC. */ 72 void ialloc_reset_free(gs_ref_memory_t *); 73 74 /* Set the cached allocation limit of an alloctor from its GC parameters. */ 75 void ialloc_set_limit(gs_ref_memory_t *); 76 77 /* Consolidate free objects. */ 78 void ialloc_consolidate_free(gs_ref_memory_t *); 79 80 #endif /* gsalloc_INCLUDED */ 81