1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/// \file
/// \brief memory management services provided by FCEU core
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../types.h"
#include "../fceu.h"
#include "memory.h"
static void *_FCEU_malloc(uint32 size)
{
#ifdef _MSC_VER
void *ret = _aligned_malloc(size,32);
#else
void *ret = aligned_alloc(32,size);
#endif
if(!ret)
{
FCEU_PrintError("Error allocating memory! Doing a hard exit.");
exit(1);
}
memset(ret, 0, size);
return ret;
}
static void _FCEU_free(void* ptr)
{
#ifdef _MSC_VER
_aligned_free(ptr);
#else
free(ptr);
#endif
}
///allocates the specified number of bytes. exits process if this fails
void *FCEU_gmalloc(uint32 size)
{
void *ret = _FCEU_malloc(size);
// initialize according to RAMInitOption, default zero
FCEU_MemoryRand((uint8*)ret,size,true);
return ret;
}
void *FCEU_malloc(uint32 size)
{
void *ret = _FCEU_malloc(size);
memset(ret, 0, size);
return ret;
}
///frees memory allocated with FCEU_gmalloc
void FCEU_gfree(void *ptr)
{
_FCEU_free(ptr);
}
///frees memory allocated with FCEU_malloc
void FCEU_free(void *ptr)
{
_FCEU_free(ptr);
}
void *FCEU_dmalloc(uint32 size)
{
return FCEU_malloc(size);
}
void FCEU_dfree(void *ptr)
{
return FCEU_free(ptr);
}
|