5 ms·
I wonder what the reaction would have been if he/she had written a blog post explaining how moving from list to numpy.array for storing numerical data in Python
by bluescarni 8y ago
I wonder what the reaction would have been if he/she had written a blog post explaining how moving from list to numpy.array for storing numerical data in Python resulted in massive performance benefits. You gotta admit the situation is kinda similar.
What is unfriendly about custom allocators? Note that in this specific case you don't need to write any allocation function, you just have to re-implement the construct() function with something that does not value-initialises if no construction arguments are provided.
- twtw 8y ago> You gotta admit the situation is kinda similar. I disagree. 1. Everybody knows Python is a scripting language, and trying to do heavy computation without handing it off to a library is going to be slow. 2. A vector is the de facto data structure for this in c++. In Python, numpy is effectively the de facto approach for math.
- bluescarni 8y agoSorry but I think this is still an apt analogy. 1. "Everybody" knows that unordered sets/maps in C++ must de-facto use chaining due to the requirements imposed by the standard. 2. numpy.array is not part of the Python standard library. It is an extra component you still need to install separately. As someone who deals regularly with novice Python users (often coming from Matlab & the likes), one of the very first points of pain/confusion is the fact that I need to teach/convince them not to use the facilities of the core language to represent "vectors".
- gpderetta 8y agoChanging the allocator changes the type of the vector, which has ABI/API implications, especially if the vector type is not under your control. Also, IMHO tying allocation with initialization in the allocator concept is not one of C++ brightest moments. There have been continuous talks about adding an unsafe_push_back and an unsafe resize for these and other reasons.
- stochastic_monk 8y agoI have written custom containers with malloc/realloc/placement new. It’s a hassle, but once it works, you have a very efficient and memory-safe implementation.