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/tilemap.c | |
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/tilemap.c')
-rw-r--r-- | src/emu/tilemap.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/emu/tilemap.c b/src/emu/tilemap.c index a4dbf235751..0e895954255 100644 --- a/src/emu/tilemap.c +++ b/src/emu/tilemap.c @@ -349,7 +349,7 @@ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info tilemap_instance = machine->tilemap_data->instance; /* allocate the tilemap itself */ - tmap = alloc_clear_or_die(tilemap_t); + tmap = auto_alloc_clear(machine, tilemap_t); /* fill in the basic metrics */ tmap->machine = machine; @@ -379,16 +379,16 @@ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info /* initialize scroll information */ tmap->scrollrows = 1; tmap->scrollcols = 1; - tmap->rowscroll = alloc_array_clear_or_die(INT32, tmap->height); - tmap->colscroll = alloc_array_clear_or_die(INT32, tmap->width); + tmap->rowscroll = auto_alloc_array_clear(machine, INT32, tmap->height); + tmap->colscroll = auto_alloc_array_clear(machine, INT32, tmap->width); /* allocate the pixel data cache */ - tmap->pixmap = bitmap_alloc(tmap->width, tmap->height, BITMAP_FORMAT_INDEXED16); + tmap->pixmap = auto_bitmap_alloc(machine, tmap->width, tmap->height, BITMAP_FORMAT_INDEXED16); /* allocate transparency mapping data */ - tmap->tileflags = alloc_array_or_die(UINT8, tmap->max_logical_index); - tmap->flagsmap = bitmap_alloc(tmap->width, tmap->height, BITMAP_FORMAT_INDEXED8); - tmap->pen_to_flags = alloc_array_clear_or_die(UINT8, MAX_PEN_TO_FLAGS * TILEMAP_NUM_GROUPS); + tmap->tileflags = auto_alloc_array(machine, UINT8, tmap->max_logical_index); + tmap->flagsmap = auto_bitmap_alloc(machine, tmap->width, tmap->height, BITMAP_FORMAT_INDEXED8); + tmap->pen_to_flags = auto_alloc_array_clear(machine, UINT8, MAX_PEN_TO_FLAGS * TILEMAP_NUM_GROUPS); for (group = 0; group < TILEMAP_NUM_GROUPS; group++) tilemap_map_pens_to_layer(tmap, group, 0, 0, TILEMAP_PIXEL_LAYER0); @@ -1155,15 +1155,15 @@ static void tilemap_dispose(tilemap_t *tmap) } /* free allocated memory */ - free(tmap->pen_to_flags); - free(tmap->tileflags); - bitmap_free(tmap->flagsmap); - bitmap_free(tmap->pixmap); - free(tmap->colscroll); - free(tmap->rowscroll); - free(tmap->logical_to_memory); - free(tmap->memory_to_logical); - free(tmap); + auto_free(tmap->machine, tmap->pen_to_flags); + auto_free(tmap->machine, tmap->tileflags); + auto_free(tmap->machine, tmap->flagsmap); + auto_free(tmap->machine, tmap->pixmap); + auto_free(tmap->machine, tmap->colscroll); + auto_free(tmap->machine, tmap->rowscroll); + auto_free(tmap->machine, tmap->logical_to_memory); + auto_free(tmap->machine, tmap->memory_to_logical); + auto_free(tmap->machine, tmap); } @@ -1195,8 +1195,8 @@ static void mappings_create(tilemap_t *tmap) tmap->max_memory_index++; /* allocate the necessary mappings */ - tmap->memory_to_logical = alloc_array_or_die(tilemap_logical_index, tmap->max_memory_index); - tmap->logical_to_memory = alloc_array_or_die(tilemap_memory_index, tmap->max_logical_index); + tmap->memory_to_logical = auto_alloc_array(tmap->machine, tilemap_logical_index, tmap->max_memory_index); + tmap->logical_to_memory = auto_alloc_array(tmap->machine, tilemap_memory_index, tmap->max_logical_index); /* update the mappings */ mappings_update(tmap); |