3 ms·
Also known as the "Struct of Arrays" approach.
by cesarb 7y ago
Also known as the "Struct of Arrays" approach.
- wtallis 7y ago"Struct of Arrays", to be contrasted with "Array of Structs", because in Java it's actually "Array of pointers to Struct". In languages where "Array of Structs" is actually possible, the decision of which to use is less clear-cut and depends on how big the Struct is, what the access patterns are like, and whether you're trying to perform SIMD operations on multiple Structs at once.
- vbezhenar 7y agoThat's not only about pointers. Every Java object incurs an overhead of around 16 bytes (architecture and JVM dependent, of course, but it's there).
- corysama 7y agoSeveral times in Python I've used the built-in CTypes library to cut down the memory footprint by using giant Arrays of (literally C) Structs.
- danudey 7y agoI was bored and had time on my hands, so I played around a bit with some of the suggestions in this thread, but it seems as though a naive ctypes approach is the worst possible approach in the two cases I tested (arrays of integers, arrays of x,y struct). Here are my code and results: https://gist.github.com/danudey/94b5442b617a734a2366e824be159beb https://gist.github.com/danudey/94b5442b617a734a2366e824be15... Is there an approach that you use that produces better results than this? Because my naive approach is unmanageably worse for both performance (not recorded) and impact on Python's memory usage.