Earlier quoted context omitted.
Probably easy enough to implement, but it'll take someone smarter than me to explain why it probably won't be an improvement.
Heap allocators already are ridiculously smart. But there's just too many divergent use cases for allocators. I wrote a simple string heap allocator (grab a 16MB block and hand out 256-byte chunks) and the resulting code was 85x* faster than jemalloc ( http://pastebin.com/dAqa4dbN ) [* I know the way I am benchmarking is shit and probably way off from real world usage, it's hard to do benchmarking ideally though.] Bu…
Please grow your buffers exponentially
121–130 of 166 posts
Re: Please grow your buffers exponentially
#122Re: Please grow your buffers exponentially
#123haha, cue firefox going back to using ridiculous amounts of memory in 5, 4, 3, 2, 1. seriously, there is no one size fits all solution and you cannot really predict who is going to end up using your code later on. or what manner they will use it in. i've worked on defects created by exponential buffer growth, as you can imagine they can be a lot worse than malloc churn.
> haha, cue firefox going back to using ridiculous amounts of memory in 5, 4, 3, 2, 1. I just had to force-kill Firefox (v. 33.0.2, on a OS X v. 10.8.1 with 4GB of memory) when it decided to not respond anymore after I had tried (silly me) to open a 14 MB XML page stored on disk. Looking in the Activity Monitor that XML file caused FF to load one of the CPUs at 100% and to use 1.5GB of memory (for opening a 14MB file…
Re: Please grow your buffers exponentially
#124That, or don't make your buffers contiguous unless you absolutely have to. I did one of those classic "100X" speedups once where the buffer was growing by a set value on every expansion. Could have gotten 10X or better improvement with exponential growth, but did even better by having an interface that didn't guarantee address-based access from one element to another, so all I needed was a tracking structure for mult…
It's not like they're difficult. I wrote one in Java not long after 1.2 came out!
Re: Please grow your buffers exponentially
#125Earlier quoted context omitted.
O(1), or O(log N)? Small difference but I was just having this argument yesterday. Each reallocation takes O(1) time (we assume), and you need O(log N) reallocations to grow by a cumulative factor of N.
By "amortized O(1)", what's meant is essentially O(1) _per array element_; in other words, O(N) overall to reach a size of N. Note that this is when considering each reallocation to take time O(current length of array) [as one has to copy over all the current elements to the new space].
Re: Please grow your buffers exponentially
#126More importantly, Firefox, please shrink your monstrous memory footprint exponentially!
Re: Please grow your buffers exponentially
#127Re: Please grow your buffers exponentially
#128http://en.wikipedia.org/wiki/Buddy_memory_allocation
The primary benefit of it is that it makes space reclamation more efficient.
(At least I think so. Might not be true with modern garbage collectors.)
Re: Please grow your buffers exponentially
#129Earlier quoted context omitted.
> haha, cue firefox going back to using ridiculous amounts of memory in 5, 4, 3, 2, 1. I just had to force-kill Firefox (v. 33.0.2, on a OS X v. 10.8.1 with 4GB of memory) when it decided to not respond anymore after I had tried (silly me) to open a 14 MB XML page stored on disk. Looking in the Activity Monitor that XML file caused FF to load one of the CPUs at 100% and to use 1.5GB of memory (for opening a 14MB file…
You can help: http://dblohm7.ca/blog/2014/08/14/diffusion-of-responsibilit...
Re: Please grow your buffers exponentially
#130More importantly, Firefox, please shrink your monstrous memory footprint exponentially!
I bet this never occured to them