News for hackers. Stuff that matters.
Re:A Fast, Growable Array with Stable Pointers in C by zokier on Wednesday August 06, 2025 @03:12PM (#44816354)
> Today’s computers use only 48 bits of the 64 bits in a pointer

https://en.wikipedia.org/wiki/Intel_5-level_paging introduced in Ice Lake 6 years ago.

But anyways, isn't this just variant of std::deque? https://en.cppreference.com/w/cpp/container/deque.html

Re:A Fast, Growable Array with Stable Pointers in C by sigbottle on Wednesday August 06, 2025 @03:31PM (#44816579)
I don't know the precise details of how deques are implemented in C++, but given the most popular stack overflow explanation of them, some immidiate pitfalls are that the T* map itself sounds unbounded and if each chunk allocates only a fixed constant size it's probably horrible for fragmentation or overallocation. The indexing also seems dependent on division.

With this power of twos approach you can't really truly delete from the front of the array but the amount of pointers you store is constant and the memory fragmentation is better. (Though OP never claimed to want to support deque behavior, it shouldn't be that hard to modify, though indexing seems like it has to go thru more arithmetic again)

I haven't used OP's array, but I have been bit plenty of times with std::deque's memory allocation patterns and had to rewrite with raw arrays and pointer tracking.

Re:A Fast, Growable Array with Stable Pointers in C by fc417fc802 on Thursday August 07, 2025 @01:42AM (#44820984)
> The indexing also seems dependent on division.

As long as the number of slots in a bucket is a power of two division reduces to right shift (I have no idea what std::deque does though). One of the advantages of not growing exponentially is that you can use a deque the way you would a ring buffer without it attempting to eat the entire address space.

Re:A Fast, Growable Array with Stable Pointers in C by cornstalks on Wednesday August 06, 2025 @03:23PM (#44816485)
What kind of setups use over 256 TiB of RAM?
Re:A Fast, Growable Array with Stable Pointers in C by TapamN on Wednesday August 06, 2025 @03:38PM (#44816685)
It not necessarily physical RAM. If you memmap large files, like maybe a large file from RAID or network share, you could still need that much virtual address space.
Re:A Fast, Growable Array with Stable Pointers in C by Dylan16807 on Friday August 08, 2025 @12:47AM (#44833523)
Do many programs want to use that much data but not control when it swaps in and out?
Re:A Fast, Growable Array with Stable Pointers in C by wittystick on Friday August 08, 2025 @08:35PM (#44843078)
No, but 5-level paging is opt-in anyway, so its presence isn't problematic if assuming a 48-bit address space. Linux won't allocate space outside the 48-bits unless you give an address hint to mmap outside the 48-bit range.
Re:A Fast, Growable Array with Stable Pointers in C by bonzini on Wednesday August 06, 2025 @03:36PM (#44816647)
In practice it's over 64 TiB because kernels often use a quarter of the available addressing space (half of the kernel addressing space) to map the physical addresses (e.g. FFFFC000_12345678 maps physical address 0x12345678). So 48 virtual address bits can be used with up to 2^46 bytes of RAM.
Re:A Fast, Growable Array with Stable Pointers in C by hinkley on Wednesday August 06, 2025 @06:18PM (#44818525)
And how long has 48 bit addressing been de rigeur? Not so long ago we had processors that could address 40 bits of address space. Or was that 38?
Re:A Fast, Growable Array with Stable Pointers in C by winocm on Wednesday August 06, 2025 @06:28PM (#44818601)
At least since maybe the DEC Alpha 21264. It could address 48-bits of VA space, but that comes with caveats due to PALcode specific intricacies.

I think VMS (or was it Tru64?) uses this mode, but many other OSes just use 43-bit or 40-bit addressing. Realistically though, I don’t think many users would be using workloads that addressed more than 38-bits worth of contiguous VA space in 1998-1999.

Re:A Fast, Growable Array with Stable Pointers in C by loeg on Wednesday August 06, 2025 @07:52PM (#44819209)
amd64 has had 48-bit addressing / 4-level paging from the beginning.
Re:A Fast, Growable Array with Stable Pointers in C by hinkley on Thursday August 07, 2025 @07:21PM (#44831612)
I must be thinking of intel’s failed 64 bit attempts prior to amd64 winning.
Re:A Fast, Growable Array with Stable Pointers in C by wittystick on Friday August 08, 2025 @08:37PM (#44843088)
Physical addresses may be limited to 40 bits, but 48-bit virtual addresses have been the norm since 4-level paging.
Re:A Fast, Growable Array with Stable Pointers in C by bonzini on Wednesday August 13, 2025 @07:09PM (#44894963)
You're probably thinking of PAE (36 bit physical address space on 32 bit virtual address space). But Intel for quite some time had a 36 bit physical address space limit on 64-bit consumer processors, even if the virtual address space was 48 bits. I think it only changed 5 years ago or less.
Re:A Fast, Growable Array with Stable Pointers in C by reorder9695 on Wednesday August 06, 2025 @03:29PM (#44816557)
"640k ought to be enough for anybody"
Re:A Fast, Growable Array with Stable Pointers in C by mwkaufma on Wednesday August 06, 2025 @03:30PM (#44816567)
In principle it's not that different that deque, though:

(1) deque uses fixed-sized blocks, not increasing-size blocks. (2) dequeue supports prepending, which adds another level of indirection internally.

Re:A Fast, Growable Array with Stable Pointers in C by sigbottle on Wednesday August 06, 2025 @03:35PM (#44816633)
You can support prepending by mirroring the allocations, probably? eg for the "negative index" case do an exponential thing in the other direction.

Your indexing has some legitimate math to be done now which can be annoying (efficiency perspective) I think you can still get o(1) with careful allocation of powers of 2.

Re:A Fast, Growable Array with Stable Pointers in C by o11c on Wednesday August 06, 2025 @04:14PM (#44817155)
That's fine if you only ever add, but is likely to fail if you pop FIFO-style. This too is ultimately fixable but means we can no longer assume "every bucket size doubles".

That said, IMO "stable pointers" is overrated; "minimize copying" is all that's useful.

Re:A Fast, Growable Array with Stable Pointers in C by dwattttt on Wednesday August 06, 2025 @05:52PM (#44818296)
Stable pointers is a limitation for simplicity's sake. If C were better at tracking pointer invalidation, we'd be better at propagating updated pointers.
Re:A Fast, Growable Array with Stable Pointers in C by sestep on Wednesday August 06, 2025 @03:26PM (#44816515)
Does std::deque support random access?
Re:A Fast, Growable Array with Stable Pointers in C by mwkaufma on Wednesday August 06, 2025 @03:28PM (#44816539)
Yes, you can see operator[] in the linked reference docs.
Re:A Fast, Growable Array with Stable Pointers in C by ksherlock on Wednesday August 06, 2025 @05:34PM (#44818114)
The cppreference documentation specifies "Random access - constant O(1)" (same as std::vector). There's a slight overhead from going through 2 pointers instead of 1 and keeping track of how many items are in the first bucket (so you know which bucket to check), but that's a constant and the big O don't care about constants.
Re:A Fast, Growable Array with Stable Pointers in C by forrestthewoods on Wednesday August 06, 2025 @05:44PM (#44818222)
std::deque details vary by implementation and is largely considered unusable for MSVC.

MSVC uses a too small block size making it worthless. libc++ block size is 16 elements or 4096 bytes.

It is generally better to use a container you can actually understand the implementation details and control.

I would not call it a variant of std::deque myself. Not wrong. But not a helpful observation imho.

Re:A Fast, Growable Array with Stable Pointers in C by penguin_booze on Thursday August 07, 2025 @02:52AM (#44821376)
What's all that icons on the diagram that illustrates 5-level paging - snowflakes and triangles?
Re:A Fast, Growable Array with Stable Pointers in C by Retr0id on Thursday August 07, 2025 @04:32AM (#44822052)
Huh, seems like a bug in the SVG renderer. The SVG itself looks normal: https://upload.wikimedia.org/wikipedia/commons/2/2b/Page_Tab...
Re:A Fast, Growable Array with Stable Pointers in C by penguin_booze on Thursday August 07, 2025 @06:19AM (#44822707)
Thanks for that. I was worried I don't understand paging anymore. FWIW, I was using Firefox.
Re:A Fast, Growable Array with Stable Pointers in C by Retr0id on Thursday August 07, 2025 @08:59AM (#44823926)
The images you see on wikipedia are rendered to a bitmap, so it's an issue on their end somewhere (and you'll see the same regardless of browser)
Re:A Fast, Growable Array with Stable Pointers in C by nly on Thursday August 07, 2025 @05:21AM (#44822336)
Unfortunately std::deque is hobbled in the Microsoft implementation. Its block size is such that if T is larger than 8 bytes it devolves to a linked list.

And it can't be fixed due to binary compatibility.

https://github.com/microsoft/STL/issues/147

By contrast the GNU implementation has a block size of 512 bytes

Fortunately in high performance systems the times where you actually want an unbounded queue are limited.