Previous 15994 Revisions Next

r11656 Wednesday 25th May, 2011 at 13:58:44 UTC by Miodrag Milanović
Removed memory allocation calls from image device,just briefly checked affected drivers (no whatsnew)
[src/emu]diimage.c diimage.h softlist.h
[src/mess/devices]sonydriv.c
[src/mess/machine]atarifdc.c msx.c nes.c

src/emu/diimage.c
r11655r11656
3939
4040#include "emu.h"
4141#include "ui.h"
42#include "pool.h"
4342#include "zippath.h"
4443
4544
r11655r11656
7069//  DEVICE IMAGE INTERFACE
7170//**************************************************************************
7271
73/*-------------------------------------------------
74    memory_error - report a memory error
75-------------------------------------------------*/
76
77static void memory_error(const char *message)
78{
79    fatalerror("%s", message);
80}
81
82
8372//-------------------------------------------------
8473//  device_image_interface - constructor
8574//-------------------------------------------------
r11655r11656
9483      m_readonly(false),
9584      m_created(false)
9685{
97   m_mempool = pool_alloc_lib(memory_error);
9886}
9987
10088
r11655r11656
10492
10593device_image_interface::~device_image_interface()
10694{
107    pool_free_lib(m_mempool);
10895}
10996
11097//-------------------------------------------------
r11655r11656
450437}
451438
452439/****************************************************************************
453  Memory allocators
454
455  These allow memory to be allocated for the lifetime of a mounted image.
456  If these (and the above accessors) are used well enough, they should be
457  able to eliminate the need for a unload function.
458****************************************************************************/
459
460void *device_image_interface::image_malloc(size_t size)
461{
462    return image_realloc(NULL, size);
463}
464
465char *device_image_interface::image_strdup(const char *src)
466{
467   return pool_strdup_lib(m_mempool, src);
468}
469
470void *device_image_interface::image_realloc(void *ptr, size_t size)
471{
472    return pool_realloc_lib(m_mempool, ptr, size);
473}
474
475void device_image_interface::image_freeptr(void *ptr)
476{
477   pool_object_remove(m_mempool, ptr, 0);
478}
479
480
481/****************************************************************************
482440  Hash info loading
483441
484442  If the hash is not checked and the relevant info not loaded, force that info
src/emu/diimage.h
r11655r11656
4646#ifndef __DIIMAGE_H__
4747#define __DIIMAGE_H__
4848
49#include "pool.h"
50
5149//**************************************************************************
5250//  TYPE DEFINITIONS
5351//**************************************************************************
r11655r11656
245243   UINT32 get_software_region_length(const char *tag);
246244   const char *get_feature(const char *feature_name);
247245
248   void *image_malloc(size_t size);
249   char *image_strdup(const char *src);
250   void *image_realloc(void *ptr, size_t size);
251   void image_freeptr(void *ptr);
252
253246   UINT32 crc();
254247   hash_collection& hash() { return m_hash; }
255248
r11655r11656
310303    int m_create_format;
311304    option_resolution *m_create_args;
312305
313   object_pool *m_mempool;
314
315306   hash_collection m_hash;
316307};
317308
src/emu/softlist.h
r11655r11656
1111
1212#include "uimenu.h"
1313#include "expat.h"
14#include "pool.h"
1415
1516
1617/*********************************************************************
src/mess/devices/sonydriv.c
r11655r11656
119119   }
120120
121121   track_size = floppy_get_track_size(fimg, f->head, floppy_drive_get_current_track(&cur_image->device()));
122   new_data = (UINT8*)cur_image->image_realloc(f->loadedtrack_data, track_size);
122   if (f->loadedtrack_data) auto_free(device->machine(),f->loadedtrack_data);
123   new_data = auto_alloc_array(device->machine(),UINT8,track_size);
123124   if (!new_data)
124125   {
125126      return;
r11655r11656
520521
521522   sony.floppy[0].is_fdhd = 0;
522523   sony.floppy[1].is_fdhd = 0;
524   sony.floppy[0].loadedtrack_data = NULL;
525   sony.floppy[1].loadedtrack_data = NULL;
523526}
524527
525528static DEVICE_IMAGE_UNLOAD( sonydriv_floppy )
src/mess/machine/nes.c
r11655r11656
16501650   state->m_fds_sides = (image.length() - header) / 65500;
16511651
16521652   if (state->m_fds_data == NULL)
1653      state->m_fds_data = (UINT8*)image.image_malloc(state->m_fds_sides * 65500);   // I don't think we can arrive here ever, probably it can be removed...
1653      state->m_fds_data = auto_alloc_array(image.device().machine(),UINT8,state->m_fds_sides * 65500);   // I don't think we can arrive here ever, probably it can be removed...
16541654
16551655   /* if there is an header, skip it */
16561656   image.fseek(header, SEEK_SET);
src/mess/machine/msx.c
r11655r11656
124124   while (size_aligned < size) {
125125      size_aligned *= 2;
126126   }
127   mem = (UINT8*)image.image_malloc(size_aligned);
127   mem = auto_alloc_array(image.device().machine(),UINT8,size_aligned);
128128   if (!mem) {
129129      logerror ("cart #%d: error: failed to allocate memory for cartridge\n",
130130                  id);
r11655r11656
177177   if (!type && size_aligned != 0x10000)
178178   {
179179      size_aligned = 0x10000;
180      mem = (UINT8*)image.image_realloc(mem, 0x10000);
180      auto_free(image.device().machine(),mem);
181      mem = auto_alloc_array(image.device().machine(),UINT8, 0x10000);
181182      if (!mem) {
182183         logerror ("cart #%d: error: cannot allocate memory\n", id);
183184         return IMAGE_INIT_FAIL;
r11655r11656
251252   }
252253
253254   /* allocate and set slot_state for this cartridge */
254   st = (slot_state*) image.image_malloc(sizeof (slot_state));
255   st = auto_alloc(image.device().machine(),slot_state);
255256   if (!st)
256257   {
257258      logerror ("cart #%d: error: cannot allocate memory for "
r11655r11656
261262   memset (st, 0, sizeof (slot_state));
262263
263264   st->m_type = type;
264   sramfile = (char*)image.image_malloc(strlen (image.filename () + 1));
265   sramfile = auto_alloc_array(image.device().machine(), char, strlen (image.filename () + 1));
265266
266267   if (sramfile) {
267268      char *ext;
src/mess/machine/atarifdc.c
r11655r11656
155155   int size, i;
156156   const char *ext;
157157
158   fdc->drv[id].image = (UINT8*)image.image_malloc(MAXSIZE);
158   fdc->drv[id].image = auto_alloc_array(image.device().machine(),UINT8,MAXSIZE);
159159   if (!fdc->drv[id].image)
160160      return;
161161
r11655r11656
180180      return;
181181   }
182182   /* re allocate the buffer; we don't want to be too lazy ;) */
183    fdc->drv[id].image = (UINT8*)image.image_realloc(fdc->drv[id].image, size);
183    //fdc->drv[id].image = (UINT8*)image.image_realloc(fdc->drv[id].image, size);
184184
185185   ext = image.filetype();
186186    /* no extension: assume XFD format (no header) */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team