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/mame.h | |
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/mame.h')
-rw-r--r-- | src/emu/mame.h | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/emu/mame.h b/src/emu/mame.h index 22537879529..65c38c295be 100644 --- a/src/emu/mame.h +++ b/src/emu/mame.h @@ -12,10 +12,9 @@ #ifndef __MAME_H__ #define __MAME_H__ -#include "mamecore.h" +#include "emucore.h" #include "video.h" #include "crsshair.h" -#include "restrack.h" #include "options.h" #include "inptport.h" #include "cpuintrf.h" @@ -27,6 +26,7 @@ #endif /* MESS */ + /*************************************************************************** CONSTANTS ***************************************************************************/ @@ -115,6 +115,23 @@ typedef enum _output_channel output_channel; /*************************************************************************** + MACROS +***************************************************************************/ + +// global allocation helpers +#define auto_alloc(m, t) pool_alloc(static_cast<running_machine *>(m)->respool, t) +#define auto_alloc_clear(m, t) pool_alloc_clear(static_cast<running_machine *>(m)->respool, t) +#define auto_alloc_array(m, t, c) pool_alloc_array(static_cast<running_machine *>(m)->respool, t, c) +#define auto_alloc_array_clear(m, t, c) pool_alloc_array_clear(static_cast<running_machine *>(m)->respool, t, c) +#define auto_free(m, v) pool_free(static_cast<running_machine *>(m)->respool, v) + +#define auto_astring_alloc(m) auto_alloc(m, astring) +#define auto_bitmap_alloc(m, w, h, f) auto_alloc(m, bitmap_t(w, h, f)) +#define auto_strdup(m, s) strcpy(auto_alloc_array(m, char, strlen(s) + 1), s) + + + +/*************************************************************************** TYPE DEFINITIONS ***************************************************************************/ @@ -178,9 +195,16 @@ struct _generic_pointers /* description of the currently-running machine */ -/* typedef struct _running_machine running_machine; -- in mamecore.h */ -struct _running_machine +class running_machine { + DISABLE_COPYING(running_machine); + +public: + running_machine(const game_driver *driver); + ~running_machine(); + + resource_pool respool; /* pool of resources for this machine */ + /* configuration data */ const machine_config * config; /* points to the constructed machine_config */ input_port_list portlist; /* points to a list of input port configurations */ |