3 ms·
Could you have achieved the same thing by just delete/free() the old arrays after copying them? I suck at manually allocating memory, have always worked in garb
by ericmcer 3y ago
Could you have achieved the same thing by just delete/free() the old arrays after copying them? I suck at manually allocating memory, have always worked in garbage collected languages where this wouldn't really be an issue.
- morcus 3y agoNo, it was actually in a (obscure scientific) garbage collected language. The syntax was roughly: `allOrbitFiles = allOrbitFiles + currentOrbitFiles`. I believe what was roughly happening under the hood was: 1. Allocate an array `tmp` of size `length of allOrbitFiles` + `length of currentOrbitFiles`. 2. Copy data from `allOrbitFiles` over to `tmp`. 3. Copy data from `currentOrbitFiles` to `tmp` 4. Reassign `allOrbitFiles` to the new array `tmp`. 5. Garbage collect the old `allOrbitFiles`. So the doubling of memory usage comes after Step 1. I would imagine (but don't know for sure) that this would actually occur in any garbage collected language I'm familiar with as well (Java, Python, Javascript).
- ericmcer 3y agoYes it would happen in JS/python/etc as well once (2 * allOrbitFiles) > Memory. Cool fix I never think about my arrays being larger than memory haha.