Skip to content

Commit 6fd3200

Browse files
committed
SNES: Replaced some callocs with malloc
These allocations are filled when the emulator is reset, we were wasting precious milliseconds zeroing them!
1 parent ee5477b commit 6fd3200

File tree

1 file changed

+35
-60
lines changed
  • retro-core/components/snes9x/src

1 file changed

+35
-60
lines changed

retro-core/components/snes9x/src/memmap.c

Lines changed: 35 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ static void Sanitize(char* str, size_t bufsize)
137137
/**********************************************************************************************/
138138
bool S9xInitMemory(void)
139139
{
140-
Memory.RAM = (uint8_t*) calloc(RAM_SIZE, 1);
141-
Memory.SRAM = (uint8_t*) calloc(SRAM_SIZE, 1);
142-
Memory.VRAM = (uint8_t*) calloc(VRAM_SIZE, 1);
143-
Memory.ROM = (uint8_t*) calloc(MAX_ROM_SIZE + 0x200, 1);
144-
Memory.FillRAM = (uint8_t*) calloc(0x8000, 1);
140+
Memory.RAM = (uint8_t*)malloc(RAM_SIZE);
141+
Memory.SRAM = (uint8_t*)malloc(SRAM_SIZE);
142+
Memory.VRAM = (uint8_t*)malloc(VRAM_SIZE);
143+
Memory.ROM = (uint8_t*)malloc(MAX_ROM_SIZE + 0x200);
144+
Memory.FillRAM = (uint8_t*)malloc(0x8000);
145145
Memory.ROM_AllocSize = MAX_ROM_SIZE + 0x200;
146146

147147
Memory.Map = (uint8_t**)calloc(MEMMAP_NUM_BLOCKS, sizeof(uint8_t*));
@@ -152,7 +152,7 @@ bool S9xInitMemory(void)
152152
IPPU.TileCache = (uint8_t*) calloc(MAX_2BIT_TILES, 128);
153153
IPPU.TileCached = (uint8_t*) calloc(MAX_2BIT_TILES, 1);
154154

155-
bytes0x2000 = (uint8_t *)calloc(0x2000, 1);
155+
bytes0x2000 = (uint8_t *)malloc(0x2000);
156156

157157
if (!Memory.RAM || !Memory.SRAM || !Memory.VRAM || !Memory.ROM || !Memory.Map || !Memory.MapInfo
158158
|| !IPPU.ScreenColors || !IPPU.TileCache || !IPPU.TileCached || !bytes0x2000)
@@ -166,66 +166,41 @@ bool S9xInitMemory(void)
166166

167167
void S9xDeinitMemory(void)
168168
{
169-
if (Memory.RAM)
170-
{
171-
free(Memory.RAM);
172-
Memory.RAM = NULL;
173-
}
174-
if (Memory.SRAM)
175-
{
176-
free(Memory.SRAM);
177-
Memory.SRAM = NULL;
178-
}
179-
if (Memory.VRAM)
180-
{
181-
free(Memory.VRAM);
182-
Memory.VRAM = NULL;
183-
}
169+
free(Memory.RAM);
170+
Memory.RAM = NULL;
171+
172+
free(Memory.SRAM);
173+
Memory.SRAM = NULL;
174+
175+
free(Memory.VRAM);
176+
Memory.VRAM = NULL;
177+
184178
if (Memory.ROM)
185-
{
186179
free(Memory.ROM - Memory.ROM_Offset);
187-
Memory.ROM_Offset = 0;
188-
Memory.ROM = NULL;
189-
}
190-
if (Memory.FillRAM)
191-
{
192-
free(Memory.FillRAM);
193-
Memory.FillRAM = NULL;
194-
}
195-
if (Memory.Map)
196-
{
197-
free(Memory.Map);
198-
Memory.Map = NULL;
199-
}
200-
if (Memory.MapInfo)
201-
{
202-
free(Memory.MapInfo);
203-
Memory.MapInfo = NULL;
204-
}
180+
Memory.ROM = NULL;
181+
Memory.ROM_Offset = 0;
182+
Memory.ROM_AllocSize = 0;
205183

206-
if (IPPU.ScreenColors)
207-
{
208-
free(IPPU.ScreenColors);
209-
IPPU.ScreenColors = NULL;
210-
}
184+
free(Memory.FillRAM);
185+
Memory.FillRAM = NULL;
211186

212-
if (IPPU.TileCached)
213-
{
214-
free(IPPU.TileCached);
215-
IPPU.TileCached = NULL;
216-
}
187+
free(Memory.Map);
188+
Memory.Map = NULL;
217189

218-
if (IPPU.TileCache)
219-
{
220-
free(IPPU.TileCache);
221-
IPPU.TileCache = NULL;
222-
}
190+
free(Memory.MapInfo);
191+
Memory.MapInfo = NULL;
223192

224-
if (bytes0x2000)
225-
{
226-
free(bytes0x2000);
227-
bytes0x2000 = NULL;
228-
}
193+
free(IPPU.ScreenColors);
194+
IPPU.ScreenColors = NULL;
195+
196+
free(IPPU.TileCached);
197+
IPPU.TileCached = NULL;
198+
199+
free(IPPU.TileCache);
200+
IPPU.TileCache = NULL;
201+
202+
free(bytes0x2000);
203+
bytes0x2000 = NULL;
229204
}
230205

231206
/**********************************************************************************************/

0 commit comments

Comments
 (0)