mirror of
https://github.com/holub/mame
synced 2025-06-03 19:36:26 +03:00

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.
95 lines
3.0 KiB
C
95 lines
3.0 KiB
C
//============================================================
|
|
//
|
|
// minimisc.c - Minimal core miscellaneous functions
|
|
//
|
|
//============================================================
|
|
//
|
|
// Copyright Aaron Giles
|
|
// All rights reserved.
|
|
//
|
|
// Redistribution and use in source and binary forms, with or
|
|
// without modification, are permitted provided that the
|
|
// following conditions are met:
|
|
//
|
|
// * Redistributions of source code must retain the above
|
|
// copyright notice, this list of conditions and the
|
|
// following disclaimer.
|
|
// * Redistributions in binary form must reproduce the
|
|
// above copyright notice, this list of conditions and
|
|
// the following disclaimer in the documentation and/or
|
|
// other materials provided with the distribution.
|
|
// * Neither the name 'MAME' nor the names of its
|
|
// contributors may be used to endorse or promote
|
|
// products derived from this software without specific
|
|
// prior written permission.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
|
|
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
// EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
|
|
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
// DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
//
|
|
//============================================================
|
|
|
|
#include "osdcore.h"
|
|
|
|
|
|
//============================================================
|
|
// osd_alloc
|
|
//============================================================
|
|
|
|
void *osd_alloc(size_t size)
|
|
{
|
|
return malloc(size);
|
|
}
|
|
|
|
|
|
//============================================================
|
|
// osd_free
|
|
//============================================================
|
|
|
|
void osd_free(void *ptr)
|
|
{
|
|
free(ptr);
|
|
}
|
|
|
|
|
|
//============================================================
|
|
// osd_alloc_executable
|
|
//============================================================
|
|
|
|
void *osd_alloc_executable(size_t size)
|
|
{
|
|
// to use this version of the code, we have to assume that
|
|
// code injected into a malloc'ed region can be safely executed
|
|
return malloc(size);
|
|
}
|
|
|
|
|
|
//============================================================
|
|
// osd_free_executable
|
|
//============================================================
|
|
|
|
void osd_free_executable(void *ptr, size_t size)
|
|
{
|
|
free(ptr);
|
|
}
|
|
|
|
|
|
//============================================================
|
|
// osd_break_into_debugger
|
|
//============================================================
|
|
|
|
void osd_break_into_debugger(const char *message)
|
|
{
|
|
// there is no standard way to do this, so ignore it
|
|
}
|