summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/vtlb.c
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2010-01-08 06:05:29 +0000
committer Aaron Giles <aaron@aarongiles.com>2010-01-08 06:05:29 +0000
commit91a1b8d634131714ec89a07496606880ea487ece (patch)
treebe1623ecd9688f97d426efe03688289e4a25f6b5 /src/emu/cpu/vtlb.c
parent26ef6355153f38264122c168438d09d1811b9530 (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/vtlb.c')
-rw-r--r--src/emu/cpu/vtlb.c16
1 files changed, 8 insertions, 8 deletions
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);
}