cpu6502 | A 6502 Instruction Set Simulator | Build Tool library
kandi X-RAY | cpu6502 Summary
kandi X-RAY | cpu6502 Summary
A 6502 Instruction Set Simulator. Includes a C++ model of the MOS 6502, with compile options, and an optional command line interface. A test program (modified) from Klaus Dormann (is included. An API is provided for integration with other applications---see src/cpu6502_api.h for more information. Support is provided for building under MSVC 2010 (cpu6502.sln) and Linux (makefile).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cpu6502
cpu6502 Key Features
cpu6502 Examples and Code Snippets
Community Discussions
Trending Discussions on cpu6502
QUESTION
I'm writing an emulator in Go, and for debugging purposes I'm logging the cpu' state at every emulator's cycle to generate a log file later.
There's something I'm not doing properly because while the logger is enabled performance drops and makes the emulator unusable.
Profiler shows clearly the culprit resides in the logging routine (logStep
method):
logStep
method is very simple, it calls CreateState
to snapshot current cpu state in a struct, and then adds it to a slice (in method Log
).
I call this method at every emulated cpu cycle (around 30.000 times per second), and I suspect either Garbage Collector is slowing my execution or I'm doing something wrong with this data structure.
I get the profile graph is pointing me to runtime growslice
caused by an append
located in (*cpu6502Logger)Log
, but I'm unable to find information on how to do this more efficiently.
Also, I scratch my head on why CreateState
takes that long to just create a simple struct.
This is what CpuState
looks like:
ANSWER
Answered 2021-May-09 at 18:26Disclaimer: following text contains grammar mistakes but i dont give a damn
why is it slowMaintaining one gigantic slice to hold all data there is is wery costy mainly when it constantly extends. Each time you append few elements, whole memory section is copied to bigges section to allow expansion. with grownig slice, complexity grows and each realocation is slower and slower. You told us that you emulate tousands of cpu states per second.
solutionThe best way to deal with this is allocating fixed buffer of some length. Now we now that eventually we will run out of space. When that happens we have two options. First you can write all data ftom buffer to file then truncate the buffer and start filling again (then write again). Other option is to save filled buffers in a slice and allocate new one. Choos witch one fits your machine. (slow or small ram is not good for second solution)
why does this helpi think this also helps the emulator it self. There will be performance spikes when restoring buffer, but most of the time, performance will be at maximum. Allocating big memory is just slow as alocator is less likely to find fitting section on first try. Garbage collection is also wery unhappy with frequent allocations. By allocating buffer and filling it, we use one big allocation, (but not too big), and store data in sections. Sections we already saved can stey where they are. We can also say that in this case we are handling memory our selfs more then gc does. (no garbage memory produced)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cpu6502
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page