Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Terje Mathisen Newsgroups: comp.arch Subject: Re: Segments Date: Thu, 16 Jan 2025 10:11:36 +0100 Organization: A noiseless patient Spider Lines: 36 Message-ID: References: <2024Oct6.150415@mips.complang.tuwien.ac.at> <2025Jan3.093849@mips.complang.tuwien.ac.at> <2025Jan5.121028@mips.complang.tuwien.ac.at> <2025Jan6.092443@mips.complang.tuwien.ac.at> <87cygo97dl.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 16 Jan 2025 10:11:37 +0100 (CET) Injection-Info: dont-email.me; posting-host="7b1eff93cc1ab65d539917eea199ebda"; logging-data="3622631"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/knJz3nNxQQAb+Sk++3fDiYdID5kGChx+6INqseQsmA==" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19 Cancel-Lock: sha1:/JIOhFR2IBPnNM+b67torPpBHQU= In-Reply-To: Bytes: 2937 Thomas Koenig wrote: > Keith Thompson schrieb: >> Thomas Koenig writes: >> [...] >>> CHERY targets C, which on the one hand, I understand (there's a >>> ton of C code out there), but trying to retrofit a safe memory >>> model onto C seems a bit awkward - it might have been better to >>> target a language which has arrays in the first place, unlike C. >> [...] >> >> C does have arrays. > > Sort of - they decay into pointers at first sight. > > But what I should have written was "multi-dimensional arrays", > with a reasonable way of handling them. > Rust provides an interesting data point here: It has Vec<> which is always implemented as a dope vector, i.e. a header which contains the starting point and current length, along with allocated size. For multidimendional work, the natural mapping is Vec>, i.e. similar to classic C arrays of arrays, but with boundary checking. However, in my own testing I have found that it is often faster to flatten those multi-dim vectors, and instead use explicit multiplication to get the actual position: array[y][x] -> array[y*width + x] Terje -- - "almost all programming can be viewed as an exercise in caching"