Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main(void) #12

Open
mgood7123 opened this issue Aug 25, 2018 · 6 comments
Open

main(void) #12

mgood7123 opened this issue Aug 25, 2018 · 6 comments

Comments

@mgood7123
Copy link

would it be possible to get it to start with main(void)

@orangeduck
Copy link
Owner

Yes you can use a local variable as the starting address instead:

int main(void) {
  int dummy;
  tgc_start(&gc, &dummy);
  
  example_function();

  tgc_stop(&gc);
}

@mgood7123
Copy link
Author

is there a possibility that when using the garbage collector the stack can become corrupted and overwrite other variables wich may be stored on the stack? Also is there a way to reduce the significant overhead occured in malloc/realloc intensive loops

@orangeduck
Copy link
Owner

orangeduck commented Aug 29, 2018

Right now the GC only reads data on the stack so it shouldn't be able to corrupt anything. The only caveat is that sometimes the stack can contain uninitialized values and technically even reading the an uninitialized value is undefined behavior so the compiler could do something crazy in this case but I don't think I've encountered any compilers that actually do anything weird.

Regarding the overhead - the most simple way to avoid any overhead is to just do malloc and free yourself instead of going via the GC. If you don't want to do it yourself (or the objects you are allocating contain pointers to other GC'd objects so need to be scanned) then no there is no way to avoid the overhead - this is what you pay for when using a GC. Obviously you can disable and re-enable the GC if you just want to avoid scans during this time period though.

@mgood7123
Copy link
Author

ok

@mgood7123
Copy link
Author

mgood7123 commented Aug 29, 2018

also when the gc recycles its memory (via tgc_run) will it recycle pointers that are still in use by accident leading to the pointer being freed, for example if i malloc a ton of stuff and assign strings to each malloced pointer will the strings still be accessable and printable or will some strings be lost due to malloc recycling

@mgood7123
Copy link
Author

turns out the recycler is not smart xP recycle with caution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants