diff options
author | 2010-01-08 06:05:29 +0000 | |
---|---|---|
committer | 2010-01-08 06:05:29 +0000 | |
commit | 91a1b8d634131714ec89a07496606880ea487ece (patch) | |
tree | be1623ecd9688f97d426efe03688289e4a25f6b5 /src/emu/cpu | |
parent | 26ef6355153f38264122c168438d09d1811b9530 (diff) |
NOTE: This change requires two new osd functions: osd_malloc() and
osd_free(). They take the same parameters as malloc() and free().
Renamed mamecore.h -> emucore.h.
New C++-aware memory manager, implemented in emualloc.*. This is a
simple manager that allows you to add any type of object to a
resource pool. Most commonly, allocated objects are added, and so
a set of allocation macros is provided to allow you to manage
objects in a particular pool:
pool_alloc(p, t) = allocate object of type 't' and add to pool 'p'
pool_alloc_clear(p, t) = same as above, but clear the memory first
pool_alloc_array(p, t, c) = allocate an array of 'c' objects of type
't' and add to pool 'p'
pool_alloc_array_clear(p, t, c) = same, but with clearing
pool_free(p, v) = free object 'v' and remove it from the pool
Note that pool_alloc[_clear] is roughly equivalent to "new t" and
pool_alloc_array[_clear] is roughly equivalent to "new t[c]". Also
note that pool_free works for single objects and arrays.
There is a single global_resource_pool defined which should be used
for any global allocations. It has equivalent macros to the pool_*
macros above that automatically target the global pool.
In addition, the memory module defines global new/delete overrides
that access file and line number parameters so that allocations can
be tracked. Currently this tracking is only done if MAME_DEBUG is
enabled. In debug builds, any unfreed memory will be printed at
the end of the session.
emualloc.h also has #defines to disable malloc/free/realloc/calloc.
Since emualloc.h is included by emucore.h, this means pretty much
all code within the emulator is forced to use the new allocators.
Although straight new/delete do work, their use is discouraged, as
any allocations made with them will not be tracked.
Changed the familar auto_alloc_* macros to map to the resource pool
model described above. The running_machine is now a class and contains
a resource pool which is automatically destructed upon deletion. If
you are a driver writer, all your allocations should be done with
auto_alloc_*.
Changed all drivers and files in the core using malloc/realloc or the
old alloc_*_or_die macros to use (preferably) the auto_alloc_* macros
instead, or the global_alloc_* macros if necessary.
Added simple C++ wrappers for astring and bitmap_t, as these need
proper constructors/destructors to be used for auto_alloc_astring and
auto_alloc_bitmap.
Removed references to the winalloc prefix file. Most of its
functionality has moved into the core, save for the guard page
allocations, which are now implemented in osd_alloc and osd_free.
Diffstat (limited to 'src/emu/cpu')
-rw-r--r-- | src/emu/cpu/adsp2100/adsp2100.c | 12 | ||||
-rw-r--r-- | src/emu/cpu/drcfe.c | 13 | ||||
-rw-r--r-- | src/emu/cpu/drcuml.c | 19 | ||||
-rw-r--r-- | src/emu/cpu/jaguar/jaguar.c | 8 | ||||
-rw-r--r-- | src/emu/cpu/se3208/se3208.c | 4 | ||||
-rw-r--r-- | src/emu/cpu/v30mz/nechost.h | 2 | ||||
-rw-r--r-- | src/emu/cpu/vtlb.c | 16 | ||||
-rw-r--r-- | src/emu/cpu/x86log.c | 4 | ||||
-rw-r--r-- | src/emu/cpu/z80/z80.c | 12 | ||||
-rw-r--r-- | src/emu/cpu/z8000/z8000tbl.c | 10 |
10 files changed, 41 insertions, 59 deletions
diff --git a/src/emu/cpu/adsp2100/adsp2100.c b/src/emu/cpu/adsp2100/adsp2100.c index 2fa1bee4ea7..aabb5349239 100644 --- a/src/emu/cpu/adsp2100/adsp2100.c +++ b/src/emu/cpu/adsp2100/adsp2100.c @@ -924,11 +924,11 @@ static int create_tables(void) /* allocate the tables */ if (!reverse_table) - reverse_table = (UINT16 *)malloc(0x4000 * sizeof(UINT16)); + reverse_table = global_alloc_array(UINT16, 0x4000); if (!mask_table) - mask_table = (UINT16 *)malloc(0x4000 * sizeof(UINT16)); + mask_table = global_alloc_array(UINT16, 0x4000); if (!condition_table) - condition_table = (UINT8 *)malloc(0x1000 * sizeof(UINT8)); + condition_table = global_alloc_array(UINT8, 0x1000); /* handle errors */ if (reverse_table == NULL || mask_table == NULL || condition_table == NULL) @@ -1010,15 +1010,15 @@ static int create_tables(void) static CPU_EXIT( adsp21xx ) { if (reverse_table != NULL) - free(reverse_table); + global_free(reverse_table); reverse_table = NULL; if (mask_table != NULL) - free(mask_table); + global_free(mask_table); mask_table = NULL; if (condition_table != NULL) - free(condition_table); + global_free(condition_table); condition_table = NULL; #if TRACK_HOTSPOTS diff --git a/src/emu/cpu/drcfe.c b/src/emu/cpu/drcfe.c index 0d7c124c063..0be7c4c65a9 100644 --- a/src/emu/cpu/drcfe.c +++ b/src/emu/cpu/drcfe.c @@ -97,7 +97,7 @@ INLINE opcode_desc *desc_alloc(drcfe_state *drcfe) if (desc != NULL) drcfe->desc_free_list = desc->next; else - desc = alloc_or_die(opcode_desc); + desc = auto_alloc(drcfe->device->machine, opcode_desc); return desc; } @@ -128,10 +128,10 @@ drcfe_state *drcfe_init(const device_config *cpu, const drcfe_config *config, vo drcfe_state *drcfe; /* allocate some memory to hold the state */ - drcfe = alloc_clear_or_die(drcfe_state); + drcfe = auto_alloc_clear(cpu->machine, drcfe_state); /* allocate the description array */ - drcfe->desc_array = alloc_array_clear_or_die(opcode_desc *, config->window_end + config->window_start + 2); + drcfe->desc_array = auto_alloc_array_clear(cpu->machine, opcode_desc *, config->window_end + config->window_start + 2); /* copy in configuration information */ drcfe->window_start = config->window_start; @@ -164,15 +164,14 @@ void drcfe_exit(drcfe_state *drcfe) { opcode_desc *freeme = drcfe->desc_free_list; drcfe->desc_free_list = drcfe->desc_free_list->next; - free(freeme); + auto_free(drcfe->device->machine, freeme); } /* free the description array */ - if (drcfe->desc_array != NULL) - free(drcfe->desc_array); + auto_free(drcfe->device->machine, drcfe->desc_array); /* free the object itself */ - free(drcfe); + auto_free(drcfe->device->machine, drcfe); } diff --git a/src/emu/cpu/drcuml.c b/src/emu/cpu/drcuml.c index cd42eae0510..d0ecfd2066c 100644 --- a/src/emu/cpu/drcuml.c +++ b/src/emu/cpu/drcuml.c @@ -646,8 +646,8 @@ void drcuml_free(drcuml_state *drcuml) /* free memory */ if (block->inst != NULL) - free(block->inst); - free(block); + auto_free(drcuml->device->machine, block->inst); + auto_free(drcuml->device->machine, block); } /* free all the symbols */ @@ -655,7 +655,7 @@ void drcuml_free(drcuml_state *drcuml) { drcuml_symbol *sym = drcuml->symlist; drcuml->symlist = sym->next; - free(sym); + auto_free(drcuml->device->machine, sym); } /* close any files */ @@ -687,18 +687,13 @@ drcuml_block *drcuml_block_begin(drcuml_state *drcuml, UINT32 maxinst, jmp_buf * if (bestblock == NULL) { /* allocate the block structure itself */ - bestblock = (drcuml_block *)malloc(sizeof(*bestblock)); - if (bestblock == NULL) - fatalerror("Out of memory allocating block in drcuml_block_begin"); - memset(bestblock, 0, sizeof(*bestblock)); + bestblock = auto_alloc_clear(drcuml->device->machine, drcuml_block); /* fill in the structure */ bestblock->drcuml = drcuml; bestblock->next = drcuml->blocklist; bestblock->maxinst = maxinst * 3 / 2; - bestblock->inst = (drcuml_instruction *)malloc(sizeof(drcuml_instruction) * bestblock->maxinst); - if (bestblock->inst == NULL) - fatalerror("Out of memory allocating instruction array in drcuml_block_begin"); + bestblock->inst = auto_alloc_array(drcuml->device->machine, drcuml_instruction, bestblock->maxinst); /* hook us into the list */ drcuml->blocklist = bestblock; @@ -1037,9 +1032,7 @@ void drcuml_symbol_add(drcuml_state *drcuml, void *base, UINT32 length, const ch drcuml_symbol *symbol; /* allocate memory to hold the symbol */ - symbol = (drcuml_symbol *)malloc(sizeof(*symbol) + strlen(name)); - if (symbol == NULL) - fatalerror("Out of memory allocating symbol in drcuml_symbol_add"); + symbol = (drcuml_symbol *)auto_alloc_array(drcuml->device->machine, UINT8, sizeof(*symbol) + strlen(name)); /* fill in the structure */ symbol->next = NULL; diff --git a/src/emu/cpu/jaguar/jaguar.c b/src/emu/cpu/jaguar/jaguar.c index 121093a21af..f272a2a419e 100644 --- a/src/emu/cpu/jaguar/jaguar.c +++ b/src/emu/cpu/jaguar/jaguar.c @@ -370,7 +370,7 @@ static void init_tables(void) } /* fill in the mirror table */ - mirror_table = alloc_array_or_die(UINT16, 65536); + mirror_table = global_alloc_array(UINT16, 65536); for (i = 0; i < 65536; i++) mirror_table[i] = ((i >> 15) & 0x0001) | ((i >> 13) & 0x0002) | ((i >> 11) & 0x0004) | ((i >> 9) & 0x0008) | @@ -382,7 +382,7 @@ static void init_tables(void) ((i << 13) & 0x4000) | ((i << 15) & 0x8000); /* fill in the condition table */ - condition_table = alloc_array_or_die(UINT8, 32 * 8); + condition_table = global_alloc_array(UINT8, 32 * 8); for (i = 0; i < 8; i++) for (j = 0; j < 32; j++) { @@ -461,11 +461,11 @@ static CPU_EXIT( jaguar ) return; if (mirror_table != NULL) - free(mirror_table); + global_free(mirror_table); mirror_table = NULL; if (condition_table != NULL) - free(condition_table); + global_free(condition_table); condition_table = NULL; } diff --git a/src/emu/cpu/se3208/se3208.c b/src/emu/cpu/se3208/se3208.c index 5839b8d2573..cdd5ec25aa8 100644 --- a/src/emu/cpu/se3208/se3208.c +++ b/src/emu/cpu/se3208/se3208.c @@ -1705,7 +1705,7 @@ static void BuildTable(void) { int i; if(!OpTable) - OpTable=alloc_array_or_die(_OP, 0x10000); + OpTable=global_alloc_array(_OP, 0x10000); for(i=0;i<0x10000;++i) OpTable[i]=DecodeOp(i); } @@ -1797,7 +1797,7 @@ static CPU_INIT( se3208 ) static CPU_EXIT( se3208 ) { if(OpTable) - free(OpTable); + global_free(OpTable); } diff --git a/src/emu/cpu/v30mz/nechost.h b/src/emu/cpu/v30mz/nechost.h index a2b5f44a03d..f0d275f1d0f 100644 --- a/src/emu/cpu/v30mz/nechost.h +++ b/src/emu/cpu/v30mz/nechost.h @@ -3,7 +3,7 @@ #define BIGCASE -#include "mamecore.h" +#include "emucore.h" typedef char BOOLEAN; diff --git a/src/emu/cpu/vtlb.c b/src/emu/cpu/vtlb.c index c8c3bc49b27..656321c69db 100644 --- a/src/emu/cpu/vtlb.c +++ b/src/emu/cpu/vtlb.c @@ -60,7 +60,7 @@ vtlb_state *vtlb_alloc(const device_config *cpu, int space, int fixed_entries, i vtlb_state *vtlb; /* allocate memory for the core structure */ - vtlb = alloc_clear_or_die(vtlb_state); + vtlb = auto_alloc_clear(cpu->machine, vtlb_state); /* fill in CPU information */ vtlb->device = cpu; @@ -77,17 +77,17 @@ vtlb_state *vtlb_alloc(const device_config *cpu, int space, int fixed_entries, i assert(vtlb->addrwidth > vtlb->pageshift); /* allocate the entry array */ - vtlb->live = alloc_array_clear_or_die(offs_t, fixed_entries + dynamic_entries); + vtlb->live = auto_alloc_array_clear(cpu->machine, offs_t, fixed_entries + dynamic_entries); state_save_register_device_item_pointer(cpu, space, vtlb->live, fixed_entries + dynamic_entries); /* allocate the lookup table */ - vtlb->table = alloc_array_clear_or_die(vtlb_entry, (size_t) 1 << (vtlb->addrwidth - vtlb->pageshift)); + vtlb->table = auto_alloc_array_clear(cpu->machine, vtlb_entry, (size_t) 1 << (vtlb->addrwidth - vtlb->pageshift)); state_save_register_device_item_pointer(cpu, space, vtlb->table, 1 << (vtlb->addrwidth - vtlb->pageshift)); /* allocate the fixed page count array */ if (fixed_entries > 0) { - vtlb->fixedpages = alloc_array_clear_or_die(int, fixed_entries); + vtlb->fixedpages = auto_alloc_array_clear(cpu->machine, int, fixed_entries); state_save_register_device_item_pointer(cpu, space, vtlb->fixedpages, fixed_entries); } return vtlb; @@ -102,16 +102,16 @@ void vtlb_free(vtlb_state *vtlb) { /* free the fixed pages if allocated */ if (vtlb->fixedpages != NULL) - free(vtlb->fixedpages); + auto_free(vtlb->device->machine, vtlb->fixedpages); /* free the table and array if they exist */ if (vtlb->live != NULL) - free(vtlb->live); + auto_free(vtlb->device->machine, vtlb->live); if (vtlb->table != NULL) - free(vtlb->table); + auto_free(vtlb->device->machine, vtlb->table); /* and then the VTLB object itself */ - free(vtlb); + auto_free(vtlb->device->machine, vtlb); } diff --git a/src/emu/cpu/x86log.c b/src/emu/cpu/x86log.c index bf61884ce58..5af2b8dad0e 100644 --- a/src/emu/cpu/x86log.c +++ b/src/emu/cpu/x86log.c @@ -91,7 +91,7 @@ x86log_context *x86log_create_context(const char *filename) x86log_context *log; /* allocate the log */ - log = alloc_clear_or_die(x86log_context); + log = global_alloc_clear(x86log_context); /* allocate the filename */ log->filename = astring_dupc(filename); @@ -114,7 +114,7 @@ void x86log_free_context(x86log_context *log) /* free the structure */ astring_free(log->filename); - free(log); + global_free(log); } diff --git a/src/emu/cpu/z80/z80.c b/src/emu/cpu/z80/z80.c index f13b97b9928..61eeef4ed5e 100644 --- a/src/emu/cpu/z80/z80.c +++ b/src/emu/cpu/z80/z80.c @@ -3362,12 +3362,8 @@ static CPU_INIT( z80 ) int oldval, newval, val; UINT8 *padd, *padc, *psub, *psbc; /* allocate big flag arrays once */ - SZHVC_add = (UINT8 *)malloc(2*256*256); - SZHVC_sub = (UINT8 *)malloc(2*256*256); - if( !SZHVC_add || !SZHVC_sub ) - { - fatalerror("Z80: failed to allocate 2 * 128K flags arrays!!!"); - } + SZHVC_add = global_alloc_array(UINT8, 2*256*256); + SZHVC_sub = global_alloc_array(UINT8, 2*256*256); padd = &SZHVC_add[ 0*256]; padc = &SZHVC_add[256*256]; psub = &SZHVC_sub[ 0*256]; @@ -3514,9 +3510,9 @@ static CPU_RESET( z80 ) static CPU_EXIT( z80 ) { - if (SZHVC_add) free(SZHVC_add); + global_free(SZHVC_add); SZHVC_add = NULL; - if (SZHVC_sub) free(SZHVC_sub); + global_free(SZHVC_sub); SZHVC_sub = NULL; } diff --git a/src/emu/cpu/z8000/z8000tbl.c b/src/emu/cpu/z8000/z8000tbl.c index 4ce36f55bac..e34ebd79888 100644 --- a/src/emu/cpu/z8000/z8000tbl.c +++ b/src/emu/cpu/z8000/z8000tbl.c @@ -545,11 +545,7 @@ void z8000_init_tables(void) int i; /* allocate the opcode execution and disassembler array */ - z8000_exec = (Z8000_exec *)malloc(0x10000 * sizeof(Z8000_exec)); - if( !z8000_exec ) - { - fatalerror("cannot allocate Z8000 execution table\n"); - } + z8000_exec = global_alloc_array(Z8000_exec, 0x10000); /* set up the zero, sign, parity lookup table */ for (i = 0; i < 256; i++) @@ -586,9 +582,7 @@ void z8000_init_tables(void) void z8000_deinit_tables(void) { - if( !z8000_exec ) - return; - free( z8000_exec ); + global_free( z8000_exec ); z8000_exec = 0; } |