Path: utzoo!utgpu!attcan!uunet!mcvax!unido!laura!hmm From: hmm@laura.UUCP (Hans-Martin Mosner) Newsgroups: comp.lang.misc Subject: Re: Dynamic array dimensioning Message-ID: <827@laura.UUCP> Date: 6 Jan 89 12:09:08 GMT References: <117400002@uxa.cso.uiuc.edu> Reply-To: hmm@laura.UUCP (Hans-Martin Mosner) Organization: University of Dortmund, W-Germany Lines: 46 In article <117400002@uxa.cso.uiuc.edu> gsg0384@uxa.cso.uiuc.edu writes: > >Hi, > >Can someone in the net enlighten me about the following? > >1. What languages support the run-time array sizing in a particular module >as in FORTRAN 8x ? Please list. These languages are quite unrelated to Fortran, but you asked for it: Smalltalk, most (all ?) Lisps, some Basics & Pascals, C (if you accept a pointer for an array and implement growing by copying) > >2 It seems (I'm not sure) impossible to dimension a local array >dynamically even in FORTRAN 8x. What languages support such dynamic >array sizing in any place as can be done in Turing? Please list. All those listed above > >3 Please list languages that cannot do either. > > FORTRAN 77, and ___________ I don't use languages that cannot do it :-) > >4. Is such dynamic array feature too costly to implement or what? This depends on what costly means to you. In general, dynamic resizing involves using a pointer to the array instead of direct addresses (this part is cheap on all sensible machines) and copying the values on each resize. The latter can be expensive, but it costs nothings as long as you don't use it, so it is exactly as expensive as not having it at all :-) Of course you need some dynamic memory allocation mechanism to get the space to copy into, but this is not very expensive if done right. If you want bounds checking, the accesses can be a little bit more expensive with variable sizes because some machines have specialized & fast boundcheck instructions with immediate (constant) operands, and the compiler will use them only if the array has fixed size. Summary: the main cost incurred is that of an additional indirection per access, which is in most cases negligible. Don't ask me why many languages don't support it. Cheers, Hans-Martin -- Hans-Martin Mosner | Don't tell Borland about Smalltalk - | hmm@unido.{uucp,bitnet} | they might invent Turbo Smalltalk ! | ------------------------------------------------------------------------ Disclaimer: Turbo Smalltalk may already be a trademark of Borland...