ROSS icon indicating copy to clipboard operation
ROSS copied to clipboard

Memory Allocation

Open mesflores opened this issue 5 years ago • 2 comments

Any recommendation, preferred examples, or documentation for managing dynamic memory allocation during simulation? I see some of the ROSS_models seem to use tw_calloc(), but I haven't found any description about its specific purpose or usage. Thanks!

mesflores avatar Jan 17 '19 04:01 mesflores

I don't think there's any documentation on that yet. Documentation is something I've been trying to work on as I get some time, but there's still a lot to do.

Basically we typically recommend not to use dynamically allocated memory, if you're using optimistic mode at all. In general, dynamic allocations can be slower, so that's why we pre-allocate our event buffers in ROSS during init. But for optimistic mode, you run into the additional problem of having to carefully choose when to free memory, because you need things to hang around in case of rollbacks. There's also technically a potential for any non-reversible library calls to cause issues in optimistic simulators, though I'm unsure how likely that is.

tw_calloc() is recommended over using actual dynamically created memory. This call will pull the memory from a memory pool. But there is no associated tw_free(), so you'd be responsible for figuring out how to manage the memory you get from the memory pool.

caitlinross avatar Jan 17 '19 16:01 caitlinross

Thanks very much! Appreciate the guidance!

mesflores avatar Jan 21 '19 17:01 mesflores