cslarsen / cslarsen/stack-machine

Memory Size

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
169
Forks
25
PR merge metrics
No merged PRs in 30d

Description

I wonder whether there is a bug in the machine implementation (or maybe I am confusing something).

- the instruction pointer points to (absolute) offsets, i.e. for next() and prev() it is increased by sizeof(int32_t). Since it is a pointer of type int32, the pointer is internally increased by sizeof(int32_t) * sizeof(int32_t).
- memory is allocated by memory(new int32_t[memsize]), but memsize itself is initialized as memsize(1000*1024*sizeof(int32_t)),

Therefore I think you are using sizeof(int32_t) more memory than actually required. I think there are two ways to resolve this:
- a) decrease memory size and access memory contents by `memory[ip/4]`
- b) decrease memory size and access memory contents by manual computation of the offset of the allocated memory `unsigned int* offset = (unsigned int*) ((unsigned char *) memory + ip);`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.