Custom Emulator for Steam release of Homebrew

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
gravelstudios
Posts: 89
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Custom Emulator for Steam release of Homebrew

Post by gravelstudios » Fri Oct 23, 2020 6:25 am

I mentioned in another thread that I'm building a custom emulator using MonoGame framework and C# in which to package my game rom for release on platforms like Steam that require the game to be a standalone exe file. After about a week of work, I have it running (not counting APU, I'm just going to import the audio files for music and sound effects). Thought I'd share a thought for anybody just starting out in programming.

I was checking task manager and noticed that my emulator was using 1.5 Gb of RAM. that's an awful lot considering what I was doing. Long story short, if any object has a Dispose() method, either use it, or put it in a using block. Finding an object that I wasn't disposing of and fixing it dropped my memory usage down to 35 Mb.

Uvixen
Posts: 3
Joined: Wed Aug 01, 2018 7:15 am

Re: Custom Emulator for Steam release of Homebrew

Post by Uvixen » Sun Oct 25, 2020 6:51 pm

gravelstudios wrote:
Fri Oct 23, 2020 6:25 am
I was checking task manager and noticed that my emulator was using 1.5 Gb of RAM. that's an awful lot considering what I was doing. Long story short, if any object has a Dispose() method, either use it, or put it in a using block. Finding an object that I wasn't disposing of and fixing it dropped my memory usage down to 35 Mb.
That's C#/.NET 101.

What IDE are you using? I thought Visual Studio 2019 had warnings for forgetting to dispose of objects, but maybe that's the SonarLint extension I have installed.

User avatar
gravelstudios
Posts: 89
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Re: Custom Emulator for Steam release of Homebrew

Post by gravelstudios » Mon Oct 26, 2020 4:54 pm

Visual Studio 2017 community. short version: I got some code off of Stack Overflow for using a Texture2D and passing a Color array to it to draw my screen. I didn't notice that I had to Dispose the Texture2D on each frame. so my emulator was basically hanging onto each frame of video until the garbage collector happened to get around to deleting it. Not very efficient.

User avatar
Dwedit
Posts: 4412
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Custom Emulator for Steam release of Homebrew

Post by Dwedit » Mon Oct 26, 2020 11:21 pm

Shouldn't really be allocating a new texture every frame, instead you should update the texture.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
gravelstudios
Posts: 89
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Re: Custom Emulator for Steam release of Homebrew

Post by gravelstudios » Tue Oct 27, 2020 5:01 am

Dwedit wrote:
Mon Oct 26, 2020 11:21 pm
Shouldn't really be allocating a new texture every frame, instead you should update the texture.
Yes, that had occurred to me also.

Post Reply