diff options
author | Aaron Giles <aaron@aarongiles.com> | 2011-04-13 20:31:00 +0000 |
---|---|---|
committer | Aaron Giles <aaron@aarongiles.com> | 2011-04-13 20:31:00 +0000 |
commit | 00d745ca7752d2f96e842a7f23e157c0d2c40bdf (patch) | |
tree | 9b6a3dcda7d0ff05b098fe0823fe4d09f6d0e6b4 /src/emu/emualloc.c | |
parent | f99e1a5da63f996cd07fae98d42c2e5ff389adef (diff) |
(Big tangle of changes that all happened as I was looking into the ROM
loader rewrite, which is still in progress....)
Replaced mamedriv.c with a new driver list mechanism that is generated
by the build tools. The emulator core now expects the presence of a
file called src/$(TARGET)/$(SUBTARGET).lst which is just a raw list of
driver names, one per line. C and C++ comments are still permitted.
This file is parsed by a new build tool makelist which extracts the
driver names, sorts them, and generates a file called drivlist.c, which
is consumed by the core. [Aaron Giles]
Added new osdcore function osd_malloc_array() which is identical to
osd_malloc() but obviously hints that the underlying allocation is for
an array. Updated all callers to use the appropriate form. Modified the
Windows allocator to only use guard pages for array-style allocations,
allowing us to enable them once again in debug builds. [Aaron Giles]
Created new static class driver_list to wrap accesses to the list of
available drivers. Improved speed of driver lookups by relying on the
presorting done by makelist. [Aaron Giles]
Created helper class driver_enumerator as a helper for iterating through
the list of drivers. This class supports basic filtering and iteration,
and also serves as a temporary cache of machine_configs. [Aaron Giles]
Created cli_frontend object to wrap all the CLI handling code in
clifront.c. Updated/simplified all the code to take advantage of the
driver_enumerator. [Aaron Giles]
Created media_auditor object to wrap all the auditing functions in
audit.c. Updated all users to the new interface. Note that the new
auditing mechanism is slightly out of sync with the romload code in
terms of finding ROMs owned by devices, so it may mis-report some
issues until the new ROM loading code is in. [Aaron Giles]
Added concept of a per-device searchpath. For most devices, their
searchpath is just the short name of the device. For driver_devices, the
searchpath is driver[;parent[;bios]]. This searchpath will eventually be
used by the rom loader to find ROMs. For now it is used by the media
auditor only. [Aaron Giles]
Created info_xml_creator object to wrap all the info generation functions
in info.c. Converted the file to C++ and cleaned up the input processing
code. [Aaron Giles]
(not for whatsnew ... Known issues: auditing of CHDs appears busted, and
debug builds report unfreed memory if you use the built-in game picker)
Diffstat (limited to 'src/emu/emualloc.c')
-rw-r--r-- | src/emu/emualloc.c | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/src/emu/emualloc.c b/src/emu/emualloc.c index 75b972e0eeb..a3164e8e913 100644 --- a/src/emu/emualloc.c +++ b/src/emu/emualloc.c @@ -92,6 +92,7 @@ public: static UINT64 s_curid; // current ID static osd_lock * s_lock; // lock for managing the list static bool s_lock_alloc; // set to true temporarily during lock allocation + static bool s_tracking; // set to true when tracking is live static memory_entry *s_hash[k_hash_prime];// hash table based on pointer static memory_entry *s_freehead; // pointer to the head of the free list @@ -118,9 +119,10 @@ resource_pool global_resource_pool; const zeromem_t zeromem = { }; // globals for memory_entry -UINT64 memory_entry::s_curid = 0; +UINT64 memory_entry::s_curid = 1; osd_lock *memory_entry::s_lock = NULL; bool memory_entry::s_lock_alloc = false; +bool memory_entry::s_tracking = false; memory_entry *memory_entry::s_hash[memory_entry::k_hash_prime] = { NULL }; memory_entry *memory_entry::s_freehead = NULL; @@ -155,6 +157,31 @@ void *malloc_file_line(size_t size, const char *file, int line) //------------------------------------------------- +// malloc_array_file_line - allocate memory with +// file and line number information, and a hint +// that this object is an array +//------------------------------------------------- + +void *malloc_array_file_line(size_t size, const char *file, int line) +{ + // allocate the memory and fail if we can't + void *result = osd_malloc_array(size); + if (result == NULL) + return NULL; + + // add a new entry + memory_entry::allocate(size, result, file, line); + +#ifdef MAME_DEBUG + // randomize the memory + rand_memory(result, size); +#endif + + return result; +} + + +//------------------------------------------------- // free_file_line - free memory with file // and line number information //------------------------------------------------- @@ -189,7 +216,19 @@ void free_file_line(void *memory, const char *file, int line) // memory //------------------------------------------------- -void dump_unfreed_mem(void) +void track_memory(bool track) +{ + memory_entry::s_tracking = track; +} + + +//------------------------------------------------- +// dump_unfreed_mem - called from the exit path +// of any code that wants to check for unfreed +// memory +//------------------------------------------------- + +void dump_unfreed_mem() { #ifdef MAME_DEBUG memory_entry::report_unfreed(); @@ -446,7 +485,7 @@ memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, if (s_freehead == NULL) { // create a new chunk, and fail if we can't - memory_entry *entry = reinterpret_cast<memory_entry *>(osd_malloc(memory_block_alloc_chunk * sizeof(memory_entry))); + memory_entry *entry = reinterpret_cast<memory_entry *>(osd_malloc_array(memory_block_alloc_chunk * sizeof(memory_entry))); if (entry == NULL) { release_lock(); @@ -468,8 +507,8 @@ memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, // populate it entry->m_size = size; entry->m_base = base; - entry->m_file = file; - entry->m_line = line; + entry->m_file = s_tracking ? file : NULL; + entry->m_line = s_tracking ? line : 0; entry->m_id = s_curid++; if (LOG_ALLOCS) fprintf(stderr, "#%06d, alloc %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast<UINT32>(entry->m_size), entry->m_file, (int)entry->m_line); @@ -561,5 +600,5 @@ void memory_entry::report_unfreed() release_lock(); if (total > 0) - fprintf(stderr, "a total of %d bytes were not free()'d\n", total); + fprintf(stderr, "a total of %d bytes were not freed\n", total); } |