Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> If you really want an arena like behavior you could allocate a byte slice and use unsafe to cast it to literally any type.

A word of caution. If you do this and then you store pointers into that slice, the GC will likely not see them (as if you were just storing them as `uintptr`s)





You need to ensure that everything you put in the arena only references stuff in the same arena.

No out pointers. If you can do that, you're fine.


I still would be wary, even in that case. Go does not guarantee that the address of an allocation won't change over the lifetime of the allocation (although current implementations do not make use of this).

If you really store just references to the same arena, better to use an offset from the start of the arena. Then it does not matter whether allocations are moved around.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: