From ce75a5d6825066fc67539c4eafed5902a34f9457 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 8 Jan 2016 12:41:13 +0100 Subject: [PATCH] removed memory tracking (nw) --- src/devices/bus/ti99x/gromport.cpp | 4 +- src/devices/cpu/vtlb.cpp | 2 +- src/devices/cpu/x86log.cpp | 2 +- src/devices/imagedev/floppy.cpp | 8 +- src/devices/sound/discrete.cpp | 6 +- src/devices/sound/discrete.h | 2 +- src/devices/sound/fm.cpp | 6 +- src/devices/sound/fm2612.cpp | 2 +- src/devices/sound/mos6581.cpp | 4 +- src/devices/sound/tiasound.cpp | 2 +- src/devices/sound/ym2413.cpp | 2 +- src/devices/sound/ymf262.cpp | 2 +- src/devices/video/polylgcy.cpp | 2 +- src/devices/video/voodoo.cpp | 2 +- src/emu/clifront.cpp | 10 +- src/emu/clifront.h | 1 - src/emu/debug/debugcon.cpp | 2 +- src/emu/debug/debugcpu.cpp | 2 +- src/emu/diimage.cpp | 2 +- src/emu/driver.h | 2 +- src/emu/emualloc.h | 29 +- src/emu/hashfile.cpp | 4 +- src/emu/machine/generic.cpp | 2 +- src/emu/romload.cpp | 2 +- src/emu/softlist.cpp | 4 +- src/emu/ui/filemngr.cpp | 4 +- src/emu/ui/imgcntrl.cpp | 14 +- src/emu/ui/inputmap.cpp | 2 +- src/emu/ui/mainmenu.cpp | 44 +- src/emu/ui/menu.cpp | 2 +- src/emu/ui/selgame.cpp | 8 +- src/emu/ui/sliders.cpp | 2 +- src/emu/ui/slotopt.cpp | 2 +- src/emu/ui/swlist.cpp | 2 +- src/emu/ui/videoopt.cpp | 2 +- src/emu/uiinput.cpp | 2 +- src/lib/formats/cassimg.cpp | 2 +- src/lib/formats/ipf_dsk.cpp | 4 +- src/lib/util/corealloc.cpp | 470 ---------------------- src/lib/util/corealloc.h | 93 +---- src/mame/machine/kay_kbd.cpp | 2 +- src/mame/video/antic.cpp | 2 +- src/mame/video/model1.cpp | 2 +- src/mame/video/model2.cpp | 4 +- src/osd/modules/debugger/debugint.cpp | 2 +- src/osd/modules/render/d3d/d3dhlsl.cpp | 4 +- src/osd/modules/render/drawd3d.cpp | 4 +- src/osd/modules/sound/coreaudio_sound.cpp | 6 +- src/osd/modules/sound/sdl_sound.cpp | 2 +- src/osd/osdnet.cpp | 2 +- src/osd/sdl/input.cpp | 2 +- src/osd/sdl/video.cpp | 4 +- src/osd/windows/input.cpp | 4 +- 53 files changed, 124 insertions(+), 675 deletions(-) delete mode 100644 src/lib/util/corealloc.cpp diff --git a/src/devices/bus/ti99x/gromport.cpp b/src/devices/bus/ti99x/gromport.cpp index ff8b780fd1d..4086daddaac 100644 --- a/src/devices/bus/ti99x/gromport.cpp +++ b/src/devices/bus/ti99x/gromport.cpp @@ -2260,7 +2260,7 @@ rpk_socket* rpk_reader::load_rom_resource(zip_file* zip, xml_data_node* rom_reso length = header->uncompressed_length; // Allocate storage - contents = global_alloc_array_clear(UINT8, length); + contents = global_alloc_array_clear(length); if (contents==nullptr) throw rpk_exception(RPK_OUT_OF_MEMORY); // and unzip file from the zip file @@ -2326,7 +2326,7 @@ rpk_socket* rpk_reader::load_ram_resource(emu_options &options, xml_data_node* r } // Allocate memory for this resource - contents = global_alloc_array_clear(UINT8, length); + contents = global_alloc_array_clear(length); if (contents==nullptr) throw rpk_exception(RPK_OUT_OF_MEMORY); //if (TRACE_RPK) logerror("gromport/RPK: Allocating RAM buffer (%d bytes) for socket '%s'\n", length, socketname); diff --git a/src/devices/cpu/vtlb.cpp b/src/devices/cpu/vtlb.cpp index 5dd5711366c..4c9a9a2f311 100644 --- a/src/devices/cpu/vtlb.cpp +++ b/src/devices/cpu/vtlb.cpp @@ -56,7 +56,7 @@ vtlb_state *vtlb_alloc(device_t *cpu, address_spacenum space, int fixed_entries, vtlb_state *vtlb; /* allocate memory for the core structure */ - vtlb = auto_alloc_clear(cpu->machine(), vtlb_state); + vtlb = auto_alloc_clear(cpu->machine(), ()); /* fill in CPU information */ vtlb->cpudevice = downcast(cpu); diff --git a/src/devices/cpu/x86log.cpp b/src/devices/cpu/x86log.cpp index 19f5287283d..c9cb81e78e9 100644 --- a/src/devices/cpu/x86log.cpp +++ b/src/devices/cpu/x86log.cpp @@ -37,7 +37,7 @@ x86log_context *x86log_create_context(const char *filename) x86log_context *log; /* allocate the log */ - log = global_alloc_clear(x86log_context); + log = global_alloc_clear(); /* allocate the filename */ log->filename.assign(filename); diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index 786a44e2916..a996a98b866 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -934,7 +934,7 @@ UINT32 floppy_image_device::get_variant() const ui_menu *floppy_image_device::get_selection_menu(running_machine &machine, render_container *container) { - return auto_alloc_clear(machine, ui_menu_control_floppy_image(machine, container, this)); + return auto_alloc_clear(machine, (machine, container, this)); } ui_menu_control_floppy_image::ui_menu_control_floppy_image(running_machine &machine, render_container *container, device_image_interface *_image) : ui_menu_control_device_image(machine, container, _image) @@ -1011,7 +1011,7 @@ void ui_menu_control_floppy_image::hook_load(std::string filename, bool softlist can_in_place = false; } submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_rw(machine(), container, can_in_place, &submenu_result))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, can_in_place, &submenu_result))); state = SELECT_RW; } @@ -1037,7 +1037,7 @@ void ui_menu_control_floppy_image::handle() format_array[total_usable++] = i; } submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_format(machine(), container, format_array, ext_match, total_usable, &submenu_result))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, format_array, ext_match, total_usable, &submenu_result))); state = SELECT_FORMAT; break; @@ -1074,7 +1074,7 @@ void ui_menu_control_floppy_image::handle() break; case ui_menu_select_rw::WRITE_OTHER: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, image, current_directory, current_file, &create_ok))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, image, current_directory, current_file, &create_ok))); state = CHECK_CREATE; break; diff --git a/src/devices/sound/discrete.cpp b/src/devices/sound/discrete.cpp index ad7e8d1875a..22b5ebe942a 100644 --- a/src/devices/sound/discrete.cpp +++ b/src/devices/sound/discrete.cpp @@ -125,7 +125,6 @@ public: int task_group; -protected: discrete_task(discrete_device &pdev) : task_group(0), m_device(pdev), m_threadid(-1), m_samples(0) { @@ -134,6 +133,7 @@ protected: m_buffers.clear(); } +protected: static void *task_callback(void *param, int threadid); inline bool process(void); @@ -698,7 +698,7 @@ void discrete_device::init_nodes(const sound_block_list_t &block_list) /* make sure we have one simple task * No need to create a node since there are no dependencies. */ - task = auto_alloc_clear(machine(), discrete_task(*this)); + task = auto_alloc_clear(machine(), (*this)); task_list.add(task); } @@ -733,7 +733,7 @@ void discrete_device::init_nodes(const sound_block_list_t &block_list) { if (task != nullptr) fatalerror("init_nodes() - Nested DISCRETE_START_TASK.\n"); - task = auto_alloc_clear(machine(), discrete_task(*this)); + task = auto_alloc_clear(machine(), (*this)); task->task_group = block->initial[0]; if (task->task_group < 0 || task->task_group >= DISCRETE_MAX_TASK_GROUPS) fatalerror("discrete_dso_task: illegal task_group %d\n", task->task_group); diff --git a/src/devices/sound/discrete.h b/src/devices/sound/discrete.h index de6c9f7ce69..e5145b39132 100644 --- a/src/devices/sound/discrete.h +++ b/src/devices/sound/discrete.h @@ -4500,7 +4500,7 @@ public: template discrete_base_node * discrete_node_factory::Create(discrete_device * pdev, const discrete_block *block) { - discrete_base_node *r = auto_alloc_clear(pdev->machine(), C); + discrete_base_node *r = auto_alloc_clear(pdev->machine(), ()); r->init(pdev, block); return r; diff --git a/src/devices/sound/fm.cpp b/src/devices/sound/fm.cpp index e6ba7979140..26888590c03 100644 --- a/src/devices/sound/fm.cpp +++ b/src/devices/sound/fm.cpp @@ -2263,7 +2263,7 @@ void * ym2203_init(void *param, device_t *device, int clock, int rate, YM2203 *F2203; /* allocate ym2203 state space */ - F2203 = auto_alloc_clear(device->machine(), YM2203); + F2203 = auto_alloc_clear(device->machine(), ()); if( !init_tables() ) { @@ -2941,7 +2941,7 @@ void * ym2608_init(void *param, device_t *device, int clock, int rate, YM2608 *F2608; /* allocate extend state space */ - F2608 = auto_alloc_clear(device->machine(), YM2608); + F2608 = auto_alloc_clear(device->machine(), ()); /* allocate total level table (128kb space) */ if( !init_tables() ) { @@ -3623,7 +3623,7 @@ void *ym2610_init(void *param, device_t *device, int clock, int rate, YM2610 *F2610; /* allocate extend state space */ - F2610 = auto_alloc_clear(device->machine(), YM2610); + F2610 = auto_alloc_clear(device->machine(), ()); /* allocate total level table (128kb space) */ if( !init_tables() ) { diff --git a/src/devices/sound/fm2612.cpp b/src/devices/sound/fm2612.cpp index 086198a9ec4..f8a35534417 100644 --- a/src/devices/sound/fm2612.cpp +++ b/src/devices/sound/fm2612.cpp @@ -2372,7 +2372,7 @@ void * ym2612_init(void *param, device_t *device, int clock, int rate, YM2612 *F2612; /* allocate extend state space */ - F2612 = auto_alloc_clear(device->machine(), YM2612); + F2612 = auto_alloc_clear(device->machine(), ()); /* allocate total level table (128kb space) */ init_tables(); diff --git a/src/devices/sound/mos6581.cpp b/src/devices/sound/mos6581.cpp index ab9dda60606..6f9a4ae24cb 100644 --- a/src/devices/sound/mos6581.cpp +++ b/src/devices/sound/mos6581.cpp @@ -45,7 +45,7 @@ mos6581_device::mos6581_device(const machine_config &mconfig, device_type type, m_stream(nullptr), m_variant(variant) { - m_token = global_alloc_clear(SID6581_t); + m_token = global_alloc_clear(); } mos6581_device::mos6581_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) @@ -56,7 +56,7 @@ mos6581_device::mos6581_device(const machine_config &mconfig, const char *tag, d m_stream(nullptr), m_variant(TYPE_6581) { - m_token = global_alloc_clear(SID6581_t); + m_token = global_alloc_clear(); } mos6581_device::~mos6581_device() diff --git a/src/devices/sound/tiasound.cpp b/src/devices/sound/tiasound.cpp index 403365c08c7..71b7b5a107e 100644 --- a/src/devices/sound/tiasound.cpp +++ b/src/devices/sound/tiasound.cpp @@ -564,7 +564,7 @@ void *tia_sound_init(device_t *device, int clock, int sample_rate, int gain) struct tia *chip; int chan; - chip = global_alloc_clear(struct tia); + chip = global_alloc_clear(); /* set the gain factor (normally use TIA_DEFAULT_GAIN) */ chip->tia_gain = gain; diff --git a/src/devices/sound/ym2413.cpp b/src/devices/sound/ym2413.cpp index 7573bfa4323..5a644815f5a 100644 --- a/src/devices/sound/ym2413.cpp +++ b/src/devices/sound/ym2413.cpp @@ -2008,7 +2008,7 @@ static YM2413 *OPLLCreate(device_t *device, int clock, int rate) if (OPLL_LockTable(device) == -1) return nullptr; /* allocate memory block */ - chip = auto_alloc_clear(device->machine(), YM2413); + chip = auto_alloc_clear(device->machine(), ()); chip->device = device; chip->clock = clock; diff --git a/src/devices/sound/ymf262.cpp b/src/devices/sound/ymf262.cpp index 84f0c22466d..333a7ecae0d 100644 --- a/src/devices/sound/ymf262.cpp +++ b/src/devices/sound/ymf262.cpp @@ -2342,7 +2342,7 @@ static OPL3 *OPL3Create(device_t *device, int clock, int rate, int type) if (OPL3_LockTable(device) == -1) return nullptr; /* allocate memory block */ - chip = auto_alloc_clear(device->machine(), OPL3); + chip = auto_alloc_clear(device->machine(), ()); chip->device = device; chip->type = type; diff --git a/src/devices/video/polylgcy.cpp b/src/devices/video/polylgcy.cpp index b18c6941515..b5daf5a924b 100644 --- a/src/devices/video/polylgcy.cpp +++ b/src/devices/video/polylgcy.cpp @@ -315,7 +315,7 @@ legacy_poly_manager *poly_alloc(running_machine &machine, int max_polys, size_t legacy_poly_manager *poly; /* allocate the manager itself */ - poly = auto_alloc_clear(machine, legacy_poly_manager); + poly = auto_alloc_clear(machine, ()); poly->flags = flags; /* allocate polygons */ diff --git a/src/devices/video/voodoo.cpp b/src/devices/video/voodoo.cpp index 0b7167fde5f..07a3c06f815 100644 --- a/src/devices/video/voodoo.cpp +++ b/src/devices/video/voodoo.cpp @@ -5841,7 +5841,7 @@ voodoo_device::voodoo_device(const machine_config &mconfig, device_type type, co m_vblank(*this), m_stall(*this) { - m_token = global_alloc_clear(voodoo_state); + m_token = global_alloc_clear(); } voodoo_device::~voodoo_device() diff --git a/src/emu/clifront.cpp b/src/emu/clifront.cpp index 465ad6f0981..6ca7cd1e738 100644 --- a/src/emu/clifront.cpp +++ b/src/emu/clifront.cpp @@ -72,11 +72,8 @@ private: cli_frontend::cli_frontend(cli_options &options, osd_interface &osd) : m_options(options), m_osd(osd), - m_result(MAMERR_NONE), - m_start_memory(next_memory_id()) + m_result(MAMERR_NONE) { - // begin tracking memory - track_memory(true); } @@ -88,11 +85,6 @@ cli_frontend::~cli_frontend() { // nuke any device options since they will leak memory m_options.remove_device_options(); - - // report any unfreed memory on clean exits - track_memory(false); - if (m_result == MAMERR_NONE) - dump_unfreed_mem(m_start_memory); } diff --git a/src/emu/clifront.h b/src/emu/clifront.h index b5613f94b76..584261660db 100644 --- a/src/emu/clifront.h +++ b/src/emu/clifront.h @@ -67,7 +67,6 @@ private: cli_options & m_options; osd_interface & m_osd; int m_result; - UINT64 m_start_memory; }; diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index b35d4afc690..9b5bd969c83 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -414,7 +414,7 @@ void debug_console_register_command(running_machine &machine, const char *comman assert_always(machine.phase() == MACHINE_PHASE_INIT, "Can only call debug_console_register_command() at init time!"); assert_always((machine.debug_flags & DEBUG_FLAG_ENABLED) != 0, "Cannot call debug_console_register_command() when debugger is not running"); - cmd = auto_alloc_clear(machine, debug_command); + cmd = auto_alloc_clear(machine, ()); /* fill in the command */ strcpy(cmd->command, command); diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index a075696b348..702d7a84802 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -116,7 +116,7 @@ void debug_cpu_init(running_machine &machine) int regnum; /* allocate and reset globals */ - machine.debugcpu_data = global = auto_alloc_clear(machine, debugcpu_private); + machine.debugcpu_data = global = auto_alloc_clear(machine, ()); global->execution_state = EXECUTION_STATE_STOPPED; global->bpindex = 1; global->wpindex = 1; diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp index c0104da34e2..99fe4c7be3b 100644 --- a/src/emu/diimage.cpp +++ b/src/emu/diimage.cpp @@ -1349,5 +1349,5 @@ void device_image_interface::software_get_default_slot(std::string &result, cons ui_menu *device_image_interface::get_selection_menu(running_machine &machine, render_container *container) { - return auto_alloc_clear(machine, ui_menu_control_device_image(machine, container, this)); + return auto_alloc_clear(machine, (machine, container, this)); } diff --git a/src/emu/driver.h b/src/emu/driver.h index 9a122bbdf42..819316f6200 100644 --- a/src/emu/driver.h +++ b/src/emu/driver.h @@ -284,7 +284,7 @@ device_t *driver_device_creator(const machine_config &mconfig, const char *tag, { assert(owner == nullptr); assert(clock == 0); - return global_alloc_clear(_DriverClass(mconfig, &driver_device_creator<_DriverClass>, tag)); + return global_alloc_clear<_DriverClass>(mconfig, &driver_device_creator<_DriverClass>, tag); } diff --git a/src/emu/emualloc.h b/src/emu/emualloc.h index 192f1fca85e..4571762054f 100644 --- a/src/emu/emualloc.h +++ b/src/emu/emualloc.h @@ -17,32 +17,15 @@ #include "osdcore.h" #include "coretmpl.h" - -//************************************************************************** -// DEBUGGING -//************************************************************************** - -// set to 1 to track memory allocated by emualloc.h itself as well -#define TRACK_SELF_MEMORY (0) - - - //************************************************************************** // MACROS //************************************************************************** -// self-allocation helpers -#if TRACK_SELF_MEMORY -#define EMUALLOC_SELF_NEW new(__FILE__, __LINE__) -#else -#define EMUALLOC_SELF_NEW new -#endif - // pool allocation helpers -#define pool_alloc(_pool, _type) (_pool).add_object(new(__FILE__, __LINE__) _type) -#define pool_alloc_clear(_pool, _type) (_pool).add_object(new(__FILE__, __LINE__, zeromem) _type) -#define pool_alloc_array(_pool, _type, _num) (_pool).add_array(new(__FILE__, __LINE__) _type[_num], (_num)) -#define pool_alloc_array_clear(_pool, _type, _num) (_pool).add_array(new(__FILE__, __LINE__, zeromem) _type[_num], (_num)) +#define pool_alloc(_pool, _type) (_pool).add_object(global_alloc(_type)) +#define pool_alloc_clear(_pool, _type) (_pool).add_object(global_alloc_clear _type) +#define pool_alloc_array(_pool, _type, _num) (_pool).add_array(global_alloc_array(_type,_num), (_num)) +#define pool_alloc_array_clear(_pool, _type, _num) (_pool).add_array(global_alloc_array_clear<_type>(_num), (_num)) #define pool_free(_pool, v) (_pool).remove(v) @@ -136,8 +119,8 @@ public: bool contains(void *ptrstart, void *ptrend); void clear(); - template _ObjectClass *add_object(_ObjectClass* object) { add(*EMUALLOC_SELF_NEW resource_pool_object<_ObjectClass>(object), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return object; } - template _ObjectClass *add_array(_ObjectClass* array, int count) { add(*EMUALLOC_SELF_NEW resource_pool_array<_ObjectClass>(array, count), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return array; } + template _ObjectClass *add_object(_ObjectClass* object) { add(*new resource_pool_object<_ObjectClass>(object), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return object; } + template _ObjectClass *add_array(_ObjectClass* array, int count) { add(*new resource_pool_array<_ObjectClass>(array, count), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return array; } private: int m_hash_size; diff --git a/src/emu/hashfile.cpp b/src/emu/hashfile.cpp index 374a09f5176..557d9c28d5f 100644 --- a/src/emu/hashfile.cpp +++ b/src/emu/hashfile.cpp @@ -604,13 +604,13 @@ bool hashfile_extrainfo(device_image_interface &image, std::string &result) static void *expat_malloc(size_t size) { - return global_alloc_array_clear(UINT8,size); + return global_alloc_array_clear(size); } static void *expat_realloc(void *ptr, size_t size) { if (ptr) global_free_array((UINT8 *)ptr); - return global_alloc_array_clear(UINT8,size); + return global_alloc_array_clear(size); } static void expat_free(void *ptr) diff --git a/src/emu/machine/generic.cpp b/src/emu/machine/generic.cpp index 2f4b94fb718..910ffda4b77 100644 --- a/src/emu/machine/generic.cpp +++ b/src/emu/machine/generic.cpp @@ -52,7 +52,7 @@ void generic_machine_init(running_machine &machine) int counternum; /* allocate our state */ - machine.generic_machine_data = auto_alloc_clear(machine, generic_machine_private); + machine.generic_machine_data = auto_alloc_clear(machine, ()); state = machine.generic_machine_data; /* reset coin counters */ diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp index c5de902a482..065a29ecf42 100644 --- a/src/emu/romload.cpp +++ b/src/emu/romload.cpp @@ -1526,7 +1526,7 @@ void rom_init(running_machine &machine) romload_private *romdata; /* allocate private data */ - machine.romload_data = romdata = auto_alloc_clear(machine, romload_private); + machine.romload_data = romdata = auto_alloc_clear(machine, ()); /* make sure we get called back on the way out */ machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(rom_exit), &machine)); diff --git a/src/emu/softlist.cpp b/src/emu/softlist.cpp index 2a5ceaccdcc..6631fa82124 100644 --- a/src/emu/softlist.cpp +++ b/src/emu/softlist.cpp @@ -703,13 +703,13 @@ softlist_parser::softlist_parser(software_list_device &list, std::string &errors void *softlist_parser::expat_malloc(size_t size) { - return global_alloc_array_clear(UINT8, size); + return global_alloc_array_clear(size); } void *softlist_parser::expat_realloc(void *ptr, size_t size) { if (ptr != nullptr) global_free_array((UINT8 *)ptr); - return global_alloc_array_clear(UINT8, size); + return global_alloc_array_clear(size); } void softlist_parser::expat_free(void *ptr) diff --git a/src/emu/ui/filemngr.cpp b/src/emu/ui/filemngr.cpp index ce94f437120..d277d0bd847 100644 --- a/src/emu/ui/filemngr.cpp +++ b/src/emu/ui/filemngr.cpp @@ -195,10 +195,10 @@ void ui_menu_file_manager::force_file_manager(running_machine &machine, render_c ui_menu::stack_reset(machine); // add the quit entry followed by the game select entry - ui_menu *quit = auto_alloc_clear(machine, ui_menu_quit_game(machine, container)); + ui_menu *quit = auto_alloc_clear(machine, (machine, container)); quit->set_special_main_menu(true); ui_menu::stack_push(quit); - ui_menu::stack_push(auto_alloc_clear(machine, ui_menu_file_manager(machine, container, warnings))); + ui_menu::stack_push(auto_alloc_clear(machine, (machine, container, warnings))); // force the menus on machine.ui().show_menu(); diff --git a/src/emu/ui/imgcntrl.cpp b/src/emu/ui/imgcntrl.cpp index 298a0e25d9c..3bb77723726 100644 --- a/src/emu/ui/imgcntrl.cpp +++ b/src/emu/ui/imgcntrl.cpp @@ -190,20 +190,20 @@ void ui_menu_control_device_image::handle() zippath_closedir(directory); } submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_selector(machine(), container, image, current_directory, current_file, true, image->image_interface()!=nullptr, can_create, &submenu_result))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, image, current_directory, current_file, true, image->image_interface()!=nullptr, can_create, &submenu_result))); state = SELECT_FILE; break; } case START_SOFTLIST: sld = nullptr; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software(machine(), container, image->image_interface(), &sld))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, image->image_interface(), &sld))); state = SELECT_SOFTLIST; break; case START_OTHER_PART: { submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, swp->interface(), &swp, true, &submenu_result))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, swi, swp->interface(), &swp, true, &submenu_result))); state = SELECT_OTHER_PART; break; } @@ -214,7 +214,7 @@ void ui_menu_control_device_image::handle() break; } software_info_name = ""; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, sld, image->image_interface(), software_info_name))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, sld, image->image_interface(), software_info_name))); state = SELECT_PARTLIST; break; @@ -226,7 +226,7 @@ void ui_menu_control_device_image::handle() { submenu_result = -1; swp = nullptr; - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_parts(machine(), container, swi, image->image_interface(), &swp, false, &submenu_result))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, swi, image->image_interface(), &swp, false, &submenu_result))); state = SELECT_ONE_PART; } else @@ -290,7 +290,7 @@ void ui_menu_control_device_image::handle() break; case ui_menu_file_selector::R_CREATE: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, image, current_directory, current_file, &create_ok))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, image, current_directory, current_file, &create_ok))); state = CHECK_CREATE; break; @@ -310,7 +310,7 @@ void ui_menu_control_device_image::handle() test_create(can_create, need_confirm); if(can_create) { if(need_confirm) { - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, &create_confirmed))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, &create_confirmed))); state = CREATE_CONFIRM; } else { state = DO_CREATE; diff --git a/src/emu/ui/inputmap.cpp b/src/emu/ui/inputmap.cpp index 3474cacee75..d72f3df1dc6 100644 --- a/src/emu/ui/inputmap.cpp +++ b/src/emu/ui/inputmap.cpp @@ -73,7 +73,7 @@ void ui_menu_input_groups::handle() /* process the menu */ const ui_menu_event *menu_event = process(0); if (menu_event != nullptr && menu_event->iptkey == IPT_UI_SELECT) - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_general(machine(), container, int((long long)(menu_event->itemref)-1)))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, int((long long)(menu_event->itemref)-1)))); } diff --git a/src/emu/ui/mainmenu.cpp b/src/emu/ui/mainmenu.cpp index 9b0e72aacad..fd2a72c016b 100644 --- a/src/emu/ui/mainmenu.cpp +++ b/src/emu/ui/mainmenu.cpp @@ -152,91 +152,91 @@ void ui_menu_main::handle() if (menu_event != nullptr && menu_event->iptkey == IPT_UI_SELECT) { switch((long long)(menu_event->itemref)) { case INPUT_GROUPS: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_groups(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case INPUT_SPECIFIC: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_specific(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case SETTINGS_DIP_SWITCHES: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_settings_dip_switches(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case SETTINGS_DRIVER_CONFIG: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_settings_driver_config(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case ANALOG: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_analog(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case BOOKKEEPING: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_bookkeeping(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case GAME_INFO: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_game_info(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case IMAGE_MENU_IMAGE_INFO: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_image_info(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case IMAGE_MENU_FILE_MANAGER: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_manager(machine(), container, nullptr))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); break; case TAPE_CONTROL: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_tape_control(machine(), container, nullptr))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); break; case PTY_INFO: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_pty_info(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case SLOT_DEVICES: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_slot_devices(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case NETWORK_DEVICES: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_network_devices(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case KEYBOARD_MODE: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_keyboard_mode(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case SLIDERS: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_sliders(machine(), container, false))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, false))); break; case VIDEO_TARGETS: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_video_targets(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case VIDEO_OPTIONS: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_video_options(machine(), container, machine().render().first_target()))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, machine().render().first_target()))); break; case CROSSHAIR: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_crosshair(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case CHEAT: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_cheat(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case SELECT_GAME: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_game(machine(), container, nullptr))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); break; case BIOS_SELECTION: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_bios_selection(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); break; case BARCODE_READ: - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_barcode_reader(machine(), container, nullptr))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); break; default: diff --git a/src/emu/ui/menu.cpp b/src/emu/ui/menu.cpp index cf3da0d8b90..e32e77ab930 100644 --- a/src/emu/ui/menu.cpp +++ b/src/emu/ui/menu.cpp @@ -1037,7 +1037,7 @@ UINT32 ui_menu::ui_handler(running_machine &machine, render_container *container { // if we have no menus stacked up, start with the main menu if (menu_stack == nullptr) - stack_push(auto_alloc_clear(machine, ui_menu_main(machine, container))); + stack_push(auto_alloc_clear(machine, (machine, container))); // update the menu state if (menu_stack != nullptr) diff --git a/src/emu/ui/selgame.cpp b/src/emu/ui/selgame.cpp index 10c39e86cc8..2bad0004f85 100644 --- a/src/emu/ui/selgame.cpp +++ b/src/emu/ui/selgame.cpp @@ -141,7 +141,7 @@ void ui_menu_select_game::inkey_select(const ui_menu_event *menu_event) // special case for configure inputs if ((FPTR)driver == 1) - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_input_groups(machine(), container))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); // anything else is a driver else @@ -180,7 +180,7 @@ void ui_menu_select_game::inkey_cancel(const ui_menu_event *menu_event) if (m_search[0] != 0) { // since we have already been popped, we must recreate ourself from scratch - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_select_game(machine(), container, nullptr))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); } } @@ -429,10 +429,10 @@ void ui_menu_select_game::force_game_select(running_machine &machine, render_con ui_menu::stack_reset(machine); // add the quit entry followed by the game select entry - ui_menu *quit = auto_alloc_clear(machine, ui_menu_quit_game(machine, container)); + ui_menu *quit = auto_alloc_clear(machine, (machine, container)); quit->set_special_main_menu(true); ui_menu::stack_push(quit); - ui_menu::stack_push(auto_alloc_clear(machine, ui_menu_select_game(machine, container, gamename))); + ui_menu::stack_push(auto_alloc_clear(machine, (machine, container, gamename))); // force the menus on machine.ui().show_menu(); diff --git a/src/emu/ui/sliders.cpp b/src/emu/ui/sliders.cpp index a7b58aeb275..26da6327202 100644 --- a/src/emu/ui/sliders.cpp +++ b/src/emu/ui/sliders.cpp @@ -242,7 +242,7 @@ UINT32 ui_menu_sliders::ui_handler(running_machine &machine, render_container *c /* if this is the first call, push the sliders menu */ if (state) - ui_menu::stack_push(auto_alloc_clear(machine, ui_menu_sliders(machine, container, true))); + ui_menu::stack_push(auto_alloc_clear(machine, (machine, container, true))); /* handle standard menus */ result = ui_menu::ui_handler(machine, container, state); diff --git a/src/emu/ui/slotopt.cpp b/src/emu/ui/slotopt.cpp index 370fe8388a7..df4d0fec6b2 100644 --- a/src/emu/ui/slotopt.cpp +++ b/src/emu/ui/slotopt.cpp @@ -204,7 +204,7 @@ void ui_menu_slot_devices::handle() device_slot_interface *slot = (device_slot_interface *)menu_event->itemref; device_slot_option *option = slot_get_current_option(slot); if (option) - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_device_config(machine(), container, slot, option))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, slot, option))); } } } diff --git a/src/emu/ui/swlist.cpp b/src/emu/ui/swlist.cpp index 6155a4c5883..64eb5109fae 100644 --- a/src/emu/ui/swlist.cpp +++ b/src/emu/ui/swlist.cpp @@ -448,7 +448,7 @@ void ui_menu_software::handle() const ui_menu_event *event = process(0); if (event != nullptr && event->iptkey == IPT_UI_SELECT) { - // ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software_list(machine(), container, (software_list_config *)event->itemref, image))); + // ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, (software_list_config *)event->itemref, image))); *m_result = (software_list_device *)event->itemref; ui_menu::stack_pop(machine()); } diff --git a/src/emu/ui/videoopt.cpp b/src/emu/ui/videoopt.cpp index c3427004008..e76c27305c8 100644 --- a/src/emu/ui/videoopt.cpp +++ b/src/emu/ui/videoopt.cpp @@ -24,7 +24,7 @@ void ui_menu_video_targets::handle() /* process the menu */ const ui_menu_event *menu_event = process(0); if (menu_event != nullptr && menu_event->iptkey == IPT_UI_SELECT) - ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_video_options(machine(), container, static_cast(menu_event->itemref)))); + ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, static_cast(menu_event->itemref)))); } diff --git a/src/emu/uiinput.cpp b/src/emu/uiinput.cpp index 8ec5c8b91cc..c84ceae865a 100644 --- a/src/emu/uiinput.cpp +++ b/src/emu/uiinput.cpp @@ -72,7 +72,7 @@ struct ui_input_private void ui_input_init(running_machine &machine) { /* create the private data */ - machine.ui_input_data = auto_alloc_clear(machine, ui_input_private); + machine.ui_input_data = auto_alloc_clear(machine, ()); machine.ui_input_data->current_mouse_x = -1; machine.ui_input_data->current_mouse_y = -1; diff --git a/src/lib/formats/cassimg.cpp b/src/lib/formats/cassimg.cpp index a591de070b1..4d7aeb0a9a3 100644 --- a/src/lib/formats/cassimg.cpp +++ b/src/lib/formats/cassimg.cpp @@ -85,7 +85,7 @@ static cassette_image *cassette_init(const struct CassetteFormat *format, void * { cassette_image *cassette; - cassette = global_alloc_clear(cassette_image); + cassette = global_alloc_clear(); cassette->format = format; cassette->io.file = file; cassette->io.procs = procs; diff --git a/src/lib/formats/ipf_dsk.cpp b/src/lib/formats/ipf_dsk.cpp index 77739da65b3..1292ce8b354 100644 --- a/src/lib/formats/ipf_dsk.cpp +++ b/src/lib/formats/ipf_dsk.cpp @@ -84,7 +84,7 @@ bool ipf_format::parse(dynamic_buffer &data, floppy_image *image) { image->set_variant(floppy_image::DSDD); // Not handling anything else yet tcount = 84*2+1; // Usual max - tinfos = global_alloc_array_clear(track_info, tcount); + tinfos = global_alloc_array_clear(tcount); bool res = scan_all_tags(data); if(res) res = generate_tracks(image); @@ -121,7 +121,7 @@ ipf_format::track_info *ipf_format::get_index(UINT32 idx) if(idx > 1000) return nullptr; if(idx >= tcount) { - auto ti1 = global_alloc_array_clear(track_info, idx+1); + auto ti1 = global_alloc_array_clear(idx+1); memcpy(ti1, tinfos, tcount*sizeof(tinfos)); global_free_array(tinfos); tcount = idx+1; diff --git a/src/lib/util/corealloc.cpp b/src/lib/util/corealloc.cpp deleted file mode 100644 index eaf0ff40420..00000000000 --- a/src/lib/util/corealloc.cpp +++ /dev/null @@ -1,470 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - corealloc.c - - Memory allocation helpers for the helper library. - -***************************************************************************/ - -#include "corealloc.h" -#include "osdcore.h" - - -//************************************************************************** -// DEBUGGING -//************************************************************************** - -#define LOG_ALLOCS (0) -#define DEBUG_MISMATCHED_ALLOCS (0) - -// define this to initialize allocated memory to a fixed non-0 value -#ifdef MAME_DEBUG -#define INITIALIZE_ALLOCATED_MEMORY -#endif - -// define this to zap memory to a fixed non-0 value before freeing -//#define OVERWRITE_FREED_MEMORY - -// compatibility with non-clang compilers -#ifndef __has_feature - #define __has_feature(x) 0 -#endif - - -//************************************************************************** -// CONSTANTS -//************************************************************************** - -// number of memory_entries to allocate in a block -const int memory_block_alloc_chunk = 256; - - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// this struct is allocated in pools to track memory allocations -// it must be a POD type!! -class memory_entry -{ -public: - // internal state - memory_entry * m_next; // link to the next entry - memory_entry * m_prev; // link to the previous entry - size_t m_size; // size of the allocation (not including this header) - void * m_base; // base of the allocation - const char * m_file; // file the allocation was made from - int m_line; // line number within that file - UINT64 m_id; // unique id - bool m_array; // array? - - // hashing prime number - static const int k_hash_prime = 6151; - - // global state - 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 - - // static helpers - static memory_entry *allocate(size_t size, void *base, const char *file, int line, bool array); - static memory_entry *find(void *ptr); - static void release(memory_entry *entry, const char *file, int line); - static void report_unfreed(UINT64 start); - -private: - static void acquire_lock(); - static void release_lock(); -}; - - - -//************************************************************************** -// GLOBALS -//************************************************************************** - -// dummy zeromem object -const zeromem_t zeromem = { }; - -// globals for memory_entry -UINT64 memory_entry::s_curid = 1; -osd_lock *memory_entry::s_lock = nullptr; -bool memory_entry::s_lock_alloc = false; -bool memory_entry::s_tracking = false; -memory_entry *memory_entry::s_hash[memory_entry::k_hash_prime] = { nullptr }; -memory_entry *memory_entry::s_freehead = nullptr; - -//************************************************************************** -// OPERATOR REPLACEMENTS -//************************************************************************** - -#ifndef NO_MEM_TRACKING - -// standard new/delete operators (try to avoid using) -void *operator new(std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, nullptr, 0, false, true, false); } -void *operator new[](std::size_t size) throw (std::bad_alloc) { return malloc_file_line(size, nullptr, 0, true, true, false); } -void operator delete(void *ptr) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, false); } -void operator delete[](void *ptr) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, true); } - -void* operator new(std::size_t size,const std::nothrow_t&) throw() { return malloc_file_line(size, nullptr, 0, false, false, false); } -void* operator new[](std::size_t size, const std::nothrow_t&) throw() { return malloc_file_line(size, nullptr, 0, true, false, false); } -void operator delete(void* ptr, const std::nothrow_t&) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, false); } -void operator delete[](void* ptr, const std::nothrow_t&) throw() { if (ptr != nullptr) free_file_line(ptr, nullptr, 0, true); } - -#endif - -//************************************************************************** -// OPERATOR OVERLOADS - DEFINITIONS -//************************************************************************** - -// file/line new/delete operators -void *operator new(std::size_t size, const char *file, int line) throw (std::bad_alloc) { return malloc_file_line(size, file, line, false, true, false); } -void *operator new[](std::size_t size, const char *file, int line) throw (std::bad_alloc) { return malloc_file_line(size, file, line, true, true, false); } -void operator delete(void *ptr, const char *file, int line) { if (ptr != nullptr) free_file_line(ptr, file, line, false); } -void operator delete[](void *ptr, const char *file, int line) { if (ptr != nullptr) free_file_line(ptr, file, line, true); } - -// file/line new/delete operators with zeroing -void *operator new(std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) { return malloc_file_line(size, file, line, false, true, true); } -void *operator new[](std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc) { return malloc_file_line(size, file, line, true, true, true); } -void operator delete(void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != nullptr) free_file_line(ptr, file, line, false); } -void operator delete[](void *ptr, const char *file, int line, const zeromem_t &) { if (ptr != nullptr) free_file_line(ptr, file, line, true); } - - - -//************************************************************************** -// GLOBAL HELPERS -//************************************************************************** - -//------------------------------------------------- -// malloc_file_line - allocate memory with file -// and line number information -//------------------------------------------------- - -void *malloc_file_line(size_t size, const char *file, int line, bool array, bool throw_on_fail, bool clear) -{ - // allocate the memory and fail if we can't - void *result = array ? osd_malloc_array(size) : osd_malloc(size); - if (result == nullptr) - { - fprintf(stderr, "Failed to allocate %d bytes (%s:%d)\n", UINT32(size), file, line); - osd_break_into_debugger("Failed to allocate RAM"); - if (throw_on_fail) - throw std::bad_alloc(); - return nullptr; - } - - // zap the memory if requested - if (clear) - memset(result, 0, size); - else - { -#if !__has_feature(memory_sanitizer) && defined(INITIALIZE_ALLOCATED_MEMORY) && !defined(MAME_DEBUG_FAST) - memset(result, 0xdd, size); -#endif - } - - // add a new entry - memory_entry::allocate(size, result, file, line, array); - - return result; -} - - -//------------------------------------------------- -// free_file_line - free memory with file -// and line number information -//------------------------------------------------- - -void free_file_line(void *memory, const char *file, int line, bool array) -{ - // find the memory entry - memory_entry *entry = memory_entry::find(memory); - - // warn about untracked frees - if (entry == nullptr) - { - fprintf(stderr, "Error: attempt to free untracked memory %p in %s(%d)!\n", memory, file, line); - osd_break_into_debugger("Error: attempt to free untracked memory"); - return; - } - - // warn about mismatched arrays - if (!array && entry->m_array) - { - fprintf(stderr, "Warning: attempt to free array %p with global_free in %s(%d)!\n", memory, file, line); - if (DEBUG_MISMATCHED_ALLOCS) { - osd_break_into_debugger("Error: attempt to free array with global_free"); - } - } - if (array && !entry->m_array) - { -#ifndef __INTEL_COMPILER // todo: fix this properly, it appears some optimization the compiler applies breaks our logic here - fprintf(stderr, "Warning: attempt to free single object %p with global_free_array in %s(%d)!\n", memory, file, line); - if (DEBUG_MISMATCHED_ALLOCS) { - osd_break_into_debugger("Error: attempt to free single object with global_free_array"); - } -#endif - } - -#ifdef OVERWRITE_FREED_MEMORY - // clear memory to a bogus value - memset(memory, 0xfc, entry->m_size); -#endif - - // free the entry and the memory - memory_entry::release(entry, file, line); - osd_free(memory); -} - -void *realloc_internal(void *memory, size_t size, const char *file, int line, bool array) -{ - fprintf(stderr, "realloc_internal called for %p in %s(%d)!\n", memory, file, line); - if(size == 0) { - return nullptr; - } - if(memory == nullptr) { - return malloc_file_line(size, file, line, array, false, false); - } - // find the memory entry - memory_entry *entry = memory_entry::find(memory); - - // warn about untracked reallocs - if (entry == nullptr) - { - fprintf(stderr, "Error: attempt to realloc untracked memory %p in %s(%d)!\n", memory, file, line); - osd_break_into_debugger("Error: attempt to realloc untracked memory"); - return memory; - } - - // this is used internally and should always be an array - if(!array || !entry->m_array) - { - fprintf(stderr, "Error: attempt to realloc non-array memory %p in %s(%d). realloc_internal should never be called directly!\n", memory, file, line); - osd_break_into_debugger("Error: attempt to realloc non-array memory"); - } - - size_t o_size = entry->m_size; - void *new_buf = malloc_file_line(size, file, line, array, false, false); - if(new_buf == nullptr) { - fprintf(stderr, "Error: realloc: unable to allocate new buffer %p in %s(%d)!\n", memory, file, line); - return nullptr; - } - memcpy(new_buf, memory, (o_size < size) ? o_size : size); - free_file_line(memory, file, line, array); - return new_buf; -} - - -//------------------------------------------------- -// track_memory - enables or disables the memory -// tracking -//------------------------------------------------- - -void track_memory(bool track) -{ - memory_entry::s_tracking = track; -} - - -//------------------------------------------------- -// next_memory_id - return the ID of the next -// allocated block -//------------------------------------------------- - -UINT64 next_memory_id() -{ - return memory_entry::s_curid; -} - - -//------------------------------------------------- -// dump_unfreed_mem - called from the exit path -// of any code that wants to check for unfreed -// memory -//------------------------------------------------- - -void dump_unfreed_mem(UINT64 start) -{ - memory_entry::report_unfreed(start); -} - - - -//************************************************************************** -// MEMORY ENTRY -//************************************************************************** - -//------------------------------------------------- -// acquire_lock - acquire the memory entry lock, -// creating a new one if needed -//------------------------------------------------- - -void memory_entry::acquire_lock() -{ - // allocate a lock on first usage - // note that osd_lock_alloc() may re-enter this path, so protect against recursion! - if (s_lock == nullptr) - { - if (s_lock_alloc) - return; - s_lock_alloc = true; - s_lock = osd_lock_alloc(); - s_lock_alloc = false; - } - osd_lock_acquire(s_lock); -} - - -//------------------------------------------------- -// release_lock - release the memory entry lock -//------------------------------------------------- - -void memory_entry::release_lock() -{ - osd_lock_release(s_lock); -} - - -//------------------------------------------------- -// allocate - allocate a new memory entry -//------------------------------------------------- - -memory_entry *memory_entry::allocate(size_t size, void *base, const char *file, int line, bool array) -{ - acquire_lock(); - - // if we're out of free entries, allocate a new chunk - if (s_freehead == nullptr) - { - // create a new chunk, and fail if we can't - memory_entry *entry = reinterpret_cast(osd_malloc_array(memory_block_alloc_chunk * sizeof(memory_entry))); - if (entry == nullptr) - { - release_lock(); - return nullptr; - } - - // add all the entries to the list - for (int entrynum = 0; entrynum < memory_block_alloc_chunk; entrynum++) - { - entry->m_next = s_freehead; - s_freehead = entry++; - } - } - - // grab a free entry - memory_entry *entry = s_freehead; - s_freehead = entry->m_next; - - // populate it - entry->m_size = size; - entry->m_base = base; - entry->m_file = s_tracking ? file : nullptr; - entry->m_line = s_tracking ? line : 0; - entry->m_id = s_curid++; - entry->m_array = array; - if (LOG_ALLOCS) - fprintf(stderr, "#%06d, alloc %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), entry->m_file, (int)entry->m_line); - - // add it to the alloc list - int hashval = reinterpret_cast(base) % k_hash_prime; - entry->m_next = s_hash[hashval]; - if (entry->m_next != nullptr) - entry->m_next->m_prev = entry; - entry->m_prev = nullptr; - s_hash[hashval] = entry; - - release_lock(); - return entry; -} - - -//------------------------------------------------- -// find - find a memory entry -//------------------------------------------------- - -memory_entry *memory_entry::find(void *ptr) -{ - // NULL maps to nothing - if (ptr == nullptr) - return nullptr; - - // scan the list under the lock - acquire_lock(); - - int hashval = reinterpret_cast(ptr) % k_hash_prime; - memory_entry *entry; - for (entry = s_hash[hashval]; entry != nullptr; entry = entry->m_next) - if (entry->m_base == ptr) - break; - - release_lock(); - return entry; -} - - -//------------------------------------------------- -// release - release a memory entry -//------------------------------------------------- - -void memory_entry::release(memory_entry *entry, const char *file, int line) -{ - acquire_lock(); - - if (LOG_ALLOCS) - fprintf(stderr, "#%06d, release %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), file, line); - - // remove ourselves from the alloc list - int hashval = reinterpret_cast(entry->m_base) % k_hash_prime; - if (entry->m_prev != nullptr) - entry->m_prev->m_next = entry->m_next; - else - s_hash[hashval] = entry->m_next; - if (entry->m_next != nullptr) - entry->m_next->m_prev = entry->m_prev; - - // add ourself to the free list - entry->m_next = s_freehead; - s_freehead = entry; - - release_lock(); -} - -/** - * @fn void memory_entry::report_unfreed(UINT64 start) - * - * @brief ------------------------------------------------- - * report_unfreed - print a list of unfreed memory to the target file - * -------------------------------------------------. - * - * @param start The start. - */ - -void memory_entry::report_unfreed(UINT64 start) -{ - acquire_lock(); - - // check for leaked memory - UINT32 total = 0; - - for (auto entry : s_hash) - for (; entry != nullptr; entry = entry->m_next) - if (entry->m_file != nullptr && entry->m_id >= start) - { - if (total == 0) - fprintf(stderr, "--- memory leak warning ---\n"); - total += entry->m_size; - fprintf(stderr, "#%06d, nofree %d bytes (%s:%d)\n", (UINT32)entry->m_id, static_cast(entry->m_size), entry->m_file, (int)entry->m_line); - } - - release_lock(); - - if (total > 0) - fprintf(stderr, "a total of %u bytes were not freed\n", total); -} diff --git a/src/lib/util/corealloc.h b/src/lib/util/corealloc.h index c4d6793562d..d5eec557afa 100644 --- a/src/lib/util/corealloc.h +++ b/src/lib/util/corealloc.h @@ -15,6 +15,8 @@ #include #include +#include +#include #include "osdcore.h" @@ -23,86 +25,29 @@ //************************************************************************** // global allocation helpers -- use these instead of new and delete -#define global_alloc(_type) new(__FILE__, __LINE__) _type -#define global_alloc_clear(_type) new(__FILE__, __LINE__, zeromem) _type -#define global_alloc_array(_type, _num) new(__FILE__, __LINE__) _type[_num] -#define global_alloc_array_clear(_type, _num) new(__FILE__, __LINE__, zeromem) _type[_num] +#define global_alloc(_type) new _type +#define global_alloc_array(_type, _num) new _type[_num] #define global_free(_ptr) do { delete _ptr; } while (0) #define global_free_array(_ptr) do { delete[] _ptr; } while (0) -//************************************************************************** -// FUNCTION PROTOTYPES -//************************************************************************** +template +inline _Tp* global_alloc_clear(_Args&&... __args) +{ + UINT8* ptr = new UINT8[sizeof(_Tp)]; // allocate memory + memset(ptr, 0, sizeof(_Tp)); + return new(ptr) _Tp(std::forward<_Args>(__args)...); +} -// allocate memory with file and line number information -void *malloc_file_line(size_t size, const char *file, int line, bool array, bool throw_on_fail, bool clear); +template +inline _Tp* global_alloc_array_clear(size_t __num) +{ + auto size = sizeof(_Tp) * __num; + UINT8* ptr = new UINT8[size]; // allocate memory + memset(ptr, 0, size); + return new(ptr) _Tp[__num](); +} -// free memory with file and line number information -void free_file_line(void *memory, const char *file, int line, bool array); -inline void free_file_line(const void *memory, const char *file, int line, bool array) { free_file_line(const_cast(memory), file, line, array); } - -// realloc with file and line number info for internal use -void *realloc_internal(void *memory, size_t size, const char *file, int line, bool array); - - -// called from the exit path of any code that wants to check for unfreed memory -void track_memory(bool track); -UINT64 next_memory_id(); -void dump_unfreed_mem(UINT64 start = 0); - - - -//************************************************************************** -// OPERATOR OVERLOADS - DECLARATIONS -//************************************************************************** - -// zeromem_t is a dummy class used to tell new to zero memory after allocation -class zeromem_t { }; - -// file/line new/delete operators -void *operator new(std::size_t size, const char *file, int line) throw (std::bad_alloc); -void *operator new[](std::size_t size, const char *file, int line) throw (std::bad_alloc); -void operator delete(void *ptr, const char *file, int line); -void operator delete[](void *ptr, const char *file, int line); - -// file/line new/delete operators with zeroing -void *operator new(std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc); -void *operator new[](std::size_t size, const char *file, int line, const zeromem_t &) throw (std::bad_alloc); -void operator delete(void *ptr, const char *file, int line, const zeromem_t &); -void operator delete[](void *ptr, const char *file, int line, const zeromem_t &); - - - -//************************************************************************** -// GLOBAL VARIABLES -//************************************************************************** - -// dummy objects to pass to the specialized new variants -extern const zeromem_t zeromem; - - - -//************************************************************************** -// ADDDITIONAL MACROS -//************************************************************************** - -#ifndef NO_MEM_TRACKING -// re-route classic malloc-style allocations -#undef malloc -#undef realloc -#undef free - -#define malloc(x) malloc_file_line(x, __FILE__, __LINE__, true, false, false) -#define realloc(x,y) realloc_internal(x, y, __FILE__, __LINE__, true, false) -#define free(x) free_file_line(x, __FILE__, __LINE__, true) - -#if !defined(_MSC_VER) || _MSC_VER < 1900 // < VS2015 -#undef calloc -#define calloc(x,y) __error_use_auto_alloc_clear_or_global_alloc_clear_instead__ -#endif - -#endif #endif /* __COREALLOC_H__ */ diff --git a/src/mame/machine/kay_kbd.cpp b/src/mame/machine/kay_kbd.cpp index 2568bd8af9c..38cf0f2391c 100644 --- a/src/mame/machine/kay_kbd.cpp +++ b/src/mame/machine/kay_kbd.cpp @@ -284,7 +284,7 @@ static const UINT8 keyboard[8][10][8] = { MACHINE_RESET_MEMBER(kaypro_state,kay_kbd) { - kay_kbd_t *kbd = m_kbd = auto_alloc_clear(machine(), kay_kbd_t); + kay_kbd_t *kbd = m_kbd = auto_alloc_clear(machine(), ()); /* disable CapsLock LED initially */ set_led_status(machine(), 1, 1); diff --git a/src/mame/video/antic.cpp b/src/mame/video/antic.cpp index 4174480ebcb..e393107bf53 100644 --- a/src/mame/video/antic.cpp +++ b/src/mame/video/antic.cpp @@ -103,7 +103,7 @@ void antic_device::device_start() prio_init(); for (int i = 0; i < m_screen->height(); i++) - m_video[i] = auto_alloc_clear(machine(), VIDEO); + m_video[i] = auto_alloc_clear(machine(),