示例#1
0
void *_malloc_or_die(size_t size, const char *file, int line)
{
	void *result;

	/* fail on attempted allocations of 0 */
	if (size == 0)
		fatalerror("Attempted to malloc zero bytes (%s:%d)", file, line);

	/* allocate and return if we succeeded */
#ifdef MALLOC_DEBUG
	result = malloc_file_line(size, file, line);
#else
	result = malloc(size);
#endif
	if (result != NULL)
	{
#ifdef MAME_DEBUG
		rand_memory(result, size);
#endif
		return result;
	}

	/* otherwise, die horribly */
	fatalerror("Failed to allocate %d bytes (%s:%d)", (int)size, file, line);
}
示例#2
0
static pool_entry *alloc_entry(memory_pool *pool, size_t buffer_size, const char *file, int line)
{
	pool_entry *entry;

	/* allocate the new entry */
	entry = malloc(offsetof(pool_entry, buffer) + buffer_size);
	if (entry == NULL)
	{
		/* failure */
		report_failure(pool, "alloc_entry: Failed to allocate %u bytes (%s:%d)", buffer_size, file, line);
		return NULL;
	}

	/* set up the new entry */
	memset(entry, 0, offsetof(pool_entry, buffer));
	entry->pool = pool;
	entry->size = buffer_size;
	entry->cookie = MAGIC_COOKIE;

	/* add this entry to the linked list */
	*pool->lastptr = entry;
	pool->lastptr = &entry->next;

#ifdef MAME_DEBUG
	/* randomize memory for debugging */
	rand_memory(entry->buffer, buffer_size);
#endif

	return entry;
}
示例#3
0
文件: cosmac.c 项目: LeWoY/MAMEHub
void cosmac_device::device_reset()
{
	m_ie = 0;
	m_q = 0;
	m_df = 0;
	rand_memory(m_r, sizeof(m_r));
}
示例#4
0
void *auto_malloc_file_line(running_machine *machine, size_t size, const char *file, int line)
{
    void *result = pool_malloc_file_line(current_pool(), size, file, line);
#ifdef MAME_DEBUG
    rand_memory(result, size);
#endif
    return result;
}
示例#5
0
void *malloc_array_file_line(size_t size, const char *file, int line)
{
	// allocate the memory and fail if we can't
	void *result = osd_malloc_array(size);
	if (result == NULL)
		return NULL;

	// add a new entry
	memory_entry::allocate(size, result, file, line);

#ifdef MAME_DEBUG
	// randomize the memory
	rand_memory(result, size);
#endif

	return result;
}