removed memory tracking (nw)

This commit is contained in:
Miodrag Milanovic 2016-01-08 12:41:13 +01:00
parent 12995ac3d4
commit ce75a5d682
53 changed files with 124 additions and 675 deletions

View File

@ -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<UINT8>(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<UINT8>(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);

View File

@ -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(), <vtlb_state>());
/* fill in CPU information */
vtlb->cpudevice = downcast<cpu_device *>(cpu);

View File

@ -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<x86log_context>();
/* allocate the filename */
log->filename.assign(filename);

View File

@ -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, <ui_menu_control_floppy_image>(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(), <ui_menu_select_rw>(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(), <ui_menu_select_format>(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(), <ui_menu_file_create>(machine(), container, image, current_directory, current_file, &create_ok)));
state = CHECK_CREATE;
break;

View File

@ -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(), <discrete_task>(*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(), <discrete_task>(*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);

View File

@ -4500,7 +4500,7 @@ public:
template <class C>
discrete_base_node * discrete_node_factory<C>::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(), <C>());
r->init(pdev, block);
return r;

View File

@ -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(), <YM2203>());
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(), <YM2608>());
/* 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(), <YM2610>());
/* allocate total level table (128kb space) */
if( !init_tables() )
{

View File

@ -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(), <YM2612>());
/* allocate total level table (128kb space) */
init_tables();

View File

@ -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<SID6581_t>();
}
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<SID6581_t>();
}
mos6581_device::~mos6581_device()

View File

@ -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<struct tia>();
/* set the gain factor (normally use TIA_DEFAULT_GAIN) */
chip->tia_gain = gain;

View File

@ -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(), <YM2413>());
chip->device = device;
chip->clock = clock;

View File

@ -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(), <OPL3>());
chip->device = device;
chip->type = type;

View File

@ -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, <legacy_poly_manager>());
poly->flags = flags;
/* allocate polygons */

View File

@ -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_state>();
}
voodoo_device::~voodoo_device()

View File

@ -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);
}

View File

@ -67,7 +67,6 @@ private:
cli_options & m_options;
osd_interface & m_osd;
int m_result;
UINT64 m_start_memory;
};

View File

@ -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, <debug_command>());
/* fill in the command */
strcpy(cmd->command, command);

View File

@ -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, <debugcpu_private>());
global->execution_state = EXECUTION_STATE_STOPPED;
global->bpindex = 1;
global->wpindex = 1;

View File

@ -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, <ui_menu_control_device_image>(machine, container, this));
}

View File

@ -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);
}

View File

@ -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<class _ObjectClass> _ObjectClass *add_object(_ObjectClass* object) { add(*EMUALLOC_SELF_NEW resource_pool_object<_ObjectClass>(object), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return object; }
template<class _ObjectClass> _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<class _ObjectClass> _ObjectClass *add_object(_ObjectClass* object) { add(*new resource_pool_object<_ObjectClass>(object), sizeof(_ObjectClass), typeid(_ObjectClass).name()); return object; }
template<class _ObjectClass> _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;

View File

@ -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<UINT8>(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<UINT8>(size);
}
static void expat_free(void *ptr)

View File

@ -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, <generic_machine_private>());
state = machine.generic_machine_data;
/* reset coin counters */

View File

@ -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, <romload_private>());
/* make sure we get called back on the way out */
machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(rom_exit), &machine));

View File

@ -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<UINT8>(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<UINT8>(size);
}
void softlist_parser::expat_free(void *ptr)

View File

@ -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, <ui_menu_quit_game>(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, <ui_menu_file_manager>(machine, container, warnings)));
// force the menus on
machine.ui().show_menu();

View File

@ -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(), <ui_menu_file_selector>(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(), <ui_menu_software>(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(), <ui_menu_software_parts>(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(), <ui_menu_software_list>(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(), <ui_menu_software_parts>(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(), <ui_menu_file_create>(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(), <ui_menu_confirm_save_as>(machine(), container, &create_confirmed)));
state = CREATE_CONFIRM;
} else {
state = DO_CREATE;

View File

@ -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(), <ui_menu_input_general>(machine(), container, int((long long)(menu_event->itemref)-1))));
}

View File

@ -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(), <ui_menu_input_groups>(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(), <ui_menu_input_specific>(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(), <ui_menu_settings_dip_switches>(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(), <ui_menu_settings_driver_config>(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(), <ui_menu_analog>(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(), <ui_menu_bookkeeping>(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(), <ui_menu_game_info>(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(), <ui_menu_image_info>(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(), <ui_menu_file_manager>(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(), <ui_menu_tape_control>(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(), <ui_menu_pty_info>(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(), <ui_menu_slot_devices>(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(), <ui_menu_network_devices>(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(), <ui_menu_keyboard_mode>(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(), <ui_menu_sliders>(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(), <ui_menu_video_targets>(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(), <ui_menu_video_options>(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(), <ui_menu_crosshair>(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(), <ui_menu_cheat>(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(), <ui_menu_select_game>(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(), <ui_menu_bios_selection>(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(), <ui_menu_barcode_reader>(machine(), container, nullptr)));
break;
default:

View File

@ -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, <ui_menu_main>(machine, container)));
// update the menu state
if (menu_stack != nullptr)

View File

@ -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(), <ui_menu_input_groups>(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(), <ui_menu_select_game>(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, <ui_menu_quit_game>(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, <ui_menu_select_game>(machine, container, gamename)));
// force the menus on
machine.ui().show_menu();

View File

@ -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, <ui_menu_sliders>(machine, container, true)));
/* handle standard menus */
result = ui_menu::ui_handler(machine, container, state);

View File

@ -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(), <ui_menu_device_config>(machine(), container, slot, option)));
}
}
}

View File

@ -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(), <ui_menu_software_list>(machine(), container, (software_list_config *)event->itemref, image)));
*m_result = (software_list_device *)event->itemref;
ui_menu::stack_pop(machine());
}

View File

@ -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<render_target *>(menu_event->itemref))));
ui_menu::stack_push(auto_alloc_clear(machine(), <ui_menu_video_options>(machine(), container, static_cast<render_target *>(menu_event->itemref))));
}

View File

@ -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, <ui_input_private>());
machine.ui_input_data->current_mouse_x = -1;
machine.ui_input_data->current_mouse_y = -1;

View File

@ -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_image>();
cassette->format = format;
cassette->io.file = file;
cassette->io.procs = procs;

View File

@ -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<track_info>(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<track_info>(idx+1);
memcpy(ti1, tinfos, tcount*sizeof(tinfos));
global_free_array(tinfos);
tcount = idx+1;

View File

@ -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<memory_entry *>(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<UINT32>(entry->m_size), entry->m_file, (int)entry->m_line);
// add it to the alloc list
int hashval = reinterpret_cast<FPTR>(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<FPTR>(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<UINT32>(entry->m_size), file, line);
// remove ourselves from the alloc list
int hashval = reinterpret_cast<FPTR>(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<UINT32>(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);
}

View File

@ -15,6 +15,8 @@
#include <stdlib.h>
#include <new>
#include <type_traits>
#include <utility>
#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<typename _Tp, typename... _Args>
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<typename _Tp>
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<void *>(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__ */

View File

@ -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(), <kay_kbd_t>());
/* disable CapsLock LED initially */
set_led_status(machine(), 1, 1);

View File

@ -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(), <VIDEO>());
/* save states */
save_pointer(NAME((UINT8 *) &m_r), sizeof(m_r));

View File

@ -1442,7 +1442,7 @@ void model1_state::tgp_scan()
VIDEO_START_MEMBER(model1_state,model1)
{
m_view = auto_alloc_clear(machine(), struct view);
m_view = auto_alloc_clear(machine(), <struct view>());
m_poly_rom = (UINT32 *)memregion("user1")->base();
m_poly_ram = make_unique_clear<UINT32[]>(0x400000);

View File

@ -279,7 +279,7 @@ static void model2_3d_init( running_machine &machine, UINT16 *texture_rom )
{
model2_state *state = machine.driver_data<model2_state>();
state->m_raster = auto_alloc_clear( machine, raster_state );
state->m_raster = auto_alloc_clear( machine, <raster_state>() );
state->m_raster->texture_rom = texture_rom;
}
@ -1197,7 +1197,7 @@ struct geo_state
static void geo_init( running_machine &machine, UINT32 *polygon_rom )
{
model2_state *state = machine.driver_data<model2_state>();
state->m_geo = auto_alloc_clear(machine, geo_state);
state->m_geo = auto_alloc_clear(machine, <geo_state>());
state->m_geo->state = state;
state->m_geo->raster = state->m_raster;

View File

@ -1319,7 +1319,7 @@ static void CreateMainMenu(running_machine &machine)
if (menu)
global_free( menu);
menu = global_alloc_clear(ui_menu_debug(machine, &machine.render().ui_container()));
menu = global_alloc_clear<ui_menu_debug>(machine, &machine.render().ui_container());
switch (focus_view->type)
{

View File

@ -1864,7 +1864,7 @@ bool shaders::register_prescaled_texture(texture_info *texture)
//============================================================
bool shaders::add_cache_target(renderer* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
{
cache_target* target = (cache_target*)global_alloc_clear(cache_target);
cache_target* target = (cache_target*)global_alloc_clear<cache_target>();
if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
{
@ -1945,7 +1945,7 @@ bool shaders::add_render_target(renderer* d3d, texture_info* info, int width, in
}
}
render_target* target = (render_target*)global_alloc_clear(render_target);
render_target* target = (render_target*)global_alloc_clear<render_target>();
if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
{

View File

@ -915,11 +915,11 @@ try_again:
// create shader options only once
if (m_shaders_options == NULL)
{
m_shaders_options = (hlsl_options*)global_alloc_clear(hlsl_options);
m_shaders_options = (hlsl_options*)global_alloc_clear<hlsl_options>();
m_shaders_options->params_init = false;
}
m_shaders = (shaders*)global_alloc_clear(shaders);
m_shaders = (shaders*)global_alloc_clear<shaders>();
m_shaders->init(d3dintf, &window().machine(), this);
int failed = m_shaders->create_resources(false);

View File

@ -146,7 +146,7 @@ private:
CFIndex const len = CFStringGetMaximumSizeForEncoding(
CFStringGetLength(str),
kCFStringEncodingUTF8);
char *const result = global_alloc_array_clear(char, len + 1);
char *const result = global_alloc_array_clear<char>(len + 1);
if (!CFStringGetCString(str, result, len + 1, kCFStringEncodingUTF8))
{
global_free_array(result);
@ -229,7 +229,7 @@ int sound_coreaudio::init(const osd_options &options)
// Allocate buffer
m_headroom = m_sample_bytes * (clamped_latency() * sample_rate() / 40);
m_buffer_size = m_sample_bytes * MAX(sample_rate() * (clamped_latency() + 3) / 40, 256);
m_buffer = global_alloc_array_clear(INT8, m_buffer_size);
m_buffer = global_alloc_array_clear<INT8>(m_buffer_size);
if (!m_buffer)
{
osd_printf_error("Could not allocate stream buffer\n");
@ -648,7 +648,7 @@ bool sound_coreaudio::get_output_device_id(
return false;
}
property_size /= sizeof(AudioDeviceID);
AudioDeviceID *const devices = global_alloc_array_clear(AudioDeviceID, property_size);
AudioDeviceID *const devices = global_alloc_array_clear<AudioDeviceID>(property_size);
property_size *= sizeof(AudioDeviceID);
err = AudioObjectGetPropertyData(
kAudioObjectSystemObject,

View File

@ -518,7 +518,7 @@ int sound_sdl::sdl_create_buffers(void)
{
osd_printf_verbose("sdl_create_buffers: creating stream buffer of %u bytes\n", stream_buffer_size);
stream_buffer = global_alloc_array_clear(INT8, stream_buffer_size);
stream_buffer = global_alloc_array_clear<INT8>(stream_buffer_size);
stream_playpos = 0;
buf_locked = 0;
return 0;

View File

@ -7,7 +7,7 @@ static class simple_list<osd_netdev::entry_t> netdev_list;
void add_netdev(const char *name, const char *description, create_netdev func)
{
auto entry = global_alloc_clear(osd_netdev::entry_t);
auto entry = global_alloc_clear<osd_netdev::entry_t>();
entry->id = netdev_list.count();
strncpy(entry->name, name, 255);
entry->name[255] = '\0';

View File

@ -2219,7 +2219,7 @@ static device_info *generic_device_alloc(device_info **devlist_head_ptr, const c
device_info *devinfo;
// allocate memory for the device object
devinfo = global_alloc_clear(device_info);
devinfo = global_alloc_clear<device_info>();
devinfo->head = devlist_head_ptr;
// allocate a UTF8 copy of the name

View File

@ -336,7 +336,7 @@ void sdl_monitor_info::add_primary_monitor(void *data)
osd_monitor_info **tailptr = &sdl_monitor_info::list;
// allocate a new monitor info
osd_monitor_info *monitor = global_alloc_clear(sdl_monitor_info(0, "", 1.0f));
osd_monitor_info *monitor = global_alloc_clear<sdl_monitor_info>(0, "", 1.0f);
//monitor->refresh();
// guess the aspect ratio assuming square pixels
@ -413,7 +413,7 @@ void sdl_monitor_info::init()
// allocate a new monitor info
monitor = global_alloc_clear(sdl_monitor_info(i, temp, 1.0f));
monitor = global_alloc_clear<sdl_monitor_info>(i, temp, 1.0f);
osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->devicename(),
monitor->position_size().width(), monitor->position_size().height());

View File

@ -858,7 +858,7 @@ static device_info *generic_device_alloc(running_machine &machine, device_info *
device_info *devinfo;
// allocate memory for the device object
devinfo = global_alloc_clear(device_info(machine));
devinfo = global_alloc_clear<device_info>(machine);
devinfo->head = devlist_head_ptr;
// allocate a UTF8 copy of the name
@ -1831,7 +1831,7 @@ static device_info *rawinput_device_create(running_machine &machine, device_info
// determine the length of the device name, allocate it, and fetch it if not nameless
if ((*get_rawinput_device_info)(device->hDevice, RIDI_DEVICENAME, NULL, &name_length) != 0)
goto error;
tname = global_alloc_array_clear(TCHAR, name_length+1);
tname = global_alloc_array_clear<TCHAR>(name_length+1);
if (name_length > 1 && (*get_rawinput_device_info)(device->hDevice, RIDI_DEVICENAME, tname, &name_length) == -1)
goto error;