I'd like to know how does the reallocation process for slices / maps
reallocation works with regards to the memory layout?
Will the allocator assign a new continuous memory area for the values to be
used? Or will it allow for segmentation, meaning the "initial area" can be
split from the "new area"?
From my (very basic) knowledge of how things work I lean towards the first
one.
The reason I'm asking this is because I wonder if there could be an option
to have a process like this:
1) define a new slice with an initial capacity, lets call this A
2) fill in the slice
3) resize for the same size as A not with a copy process but rather by
allocating a new zone B
4) fill the new zone as well
5) repeat 3) two - six more times
6) after 5 happens a few times reallocate everything in a new, continuous
memory area
7) now consider the new memory area as zone A and continue with it from 2)
as needed
This could lead maybe to some improvements in the compiler / runtime which
could detect when allocations happen in a loop (say write lots of entries
in a slice) and, at the end of the loop, unify all the segments in a single
zone for example.
Might not be the brightest idea as you need always to have 2x the memory
size of your slice available (unless the performance impact for leaving the
memory fragmented is small enough). On the other hand, the throughput in
creating such an slice / map should be increased due to less copying around
of elements when reallocation happens (no?)
Thank you.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.