Timeline for Do any languages provide arrays that are always powers of 2 in length?
Current License: CC BY-SA 4.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 15, 2023 at 22:52 | comment | added | Moonchild | Historically, gpus frequently only supported textures with power-of-two sizes, though nowadays they are not so restricted. Behaviour of out-of-bounds accesses is configurable; see this graphic. | |
| Jul 1, 2023 at 16:52 | comment | added | Ray Butterworth | @KarlKnechtel, no, I'm sure it was a one-off and long gone. I'm just curious as to whether anyone else ever implemented it. It potentially wastes a bit of space, but it simplifies other things. For instance the question of whether arrays are origin 0 or origin 1 is meaningless. And if you want to keep track of the latest say 16 instances of something, no bookkeeping is required. | |
| Jul 1, 2023 at 16:00 | comment | added | Karl Knechtel | I can't understand the meaning of "real" that you're after. Are we just trying to figure out which language you were working with, for example? | |
| Jun 30, 2023 at 18:44 | comment | added | Ray Butterworth | Amusingly, my archives record that I posted this to a newsgroup in 1984: "… any program that uses stdio can save as much as 50% in buffer space if we just redefined BUFSIZ as 1020 instead of 1024.". In a style typical of the flame-wars of the time, my blasphemy was kindly and logically refuted: "I don't get it. You're obviously just being a f___ing a__h____.". | |
| Jun 30, 2023 at 18:12 | comment | added | Pablo H | Windows low fragmentation heap causes that many (small) allocations are powers of 2. | |
| Jun 30, 2023 at 2:38 | comment | added | Ray Butterworth | @RydwolfPrograms, I should add that the documentation for standard stdio functions also encouraged this use of inefficient buffer size. e.g. setvbuf(…, malloc(BUFSIZ), …, BUFSIZ), where BUFSIZ is almost always defined as a power of 2. | |
| Jun 30, 2023 at 2:25 | comment | added | Ray Butterworth | @RydwolfPrograms, I remember implementations of malloc() , perhaps the original BSD, where the allocated blocks were a power of 2, but the first 4 bytes were used to store the size of the block for use by free() . This meant that the common practice of buffer=malloc(1024) actually used 2048 bytes. 1024 was an obvious choice, but in fact it was the worst possible choice. | |
| Jun 30, 2023 at 1:21 | comment | added | rydwolf | While it's not an answer to the question as described, a related fun fact is that the growth factor in many languages' implementations of dynamic arrays is 2, so if the initial size of the array is a power of two, it will always have a power of two capacity. | |
| Jun 30, 2023 at 0:49 | history | asked | Ray Butterworth | CC BY-SA 4.0 |