Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-07

Two simple dynamic arrays questions

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alan Mead

Hi, I am new to dynamic/open arrays. I've installed 1.9.4 and played with the example code, read the docs, and converted a sample program that I'd written using static arrays to dynamic. I have two residual questions:

(1) Previously, I had fillchar'd the static arrays with zeros because they are sparse-ish. Looks like dynamic arrays are automagically filled with zeros. Is this true/permanent? Or a lucky coincidence that I shouldn't count upon? If the later, is there a fast one-liner like fillchar that I can use to initalize array to zeros?

(2) There is no way, I supposed, to switch the array indexes to start at 1 is there? I ask not from intrasigence but because I am using matricies and it rains on my elegance parade to have to perform the trivial translation each time I want to access an element using absolute row/column addresses. I also have a lot of older code and I'll have to hunt through it and make this change everywhere...

Thanks!

-Alan

Reply by email

Jonas Maebe
to Alan Mead
Alan Mead wrote
(1) Previously, I had fillchar'd the static arrays with zeros because they are sparse-ish. Looks like dynamic arrays are automagically filled with zeros. Is this true/permanent?

Yes.

(2) There is no way, I supposed, to switch the array indexes to start at 1 is there?

No, there is unfortunately no way to do this.

Jonas

Reply by email

Eduardo Morras
to Alan Mead: Hi, I am new to dynamic/open arrays. I've installed 1.9.4 and played with the example…
you wrote 6 lines
(2) There is no way, I supposed, to switch the array indexes to start at 1 is there? I ask not from intrasigence but because I am using matricies and it rains on my elegance parade to have to perform the trivial translation each time I want to access an element using absolute row/column addresses. I also have a lot of older code and I'll have to hunt through it and make this change everywhere...

Just fill the [0] position with 0 or any other value and ignore it, begining using at [1].

Thanks!

************************************************************************************************************************************************** This document represent my ideas. They are original from me. It's forbidden think the same than me, without previous payment.
If you agree me, PAY. If you don't do so, you are infringing the copyrigth laws. If you divulge my ideas in any media, you will be hunt, skin and cook.

Reply by email

Cox, Stuart TRAN:EX

Would not allocating the dynamic arrays a single element greater in size not permit you to address their elements the way you'd like. I.e.: for a five element array, allocate size 6 and get [0..5] and then use only [1..5]? Just pretend that the [0] position doesn't exist. Of Course, you'd have to be careful with low(x) as the index starting spot. If this is too easy what am I missing?

Stu

Earlier message 26 lines
-----Original Message----- From: On Behalf Of Jonas Maebe Sent: Wednesday, July 28, 2004 12:00 PM To: Subject: Re: [fpc-pascal]Two simple dynamic arrays questions On 28 jul 2004, at 19:48, Alan Mead wrote: > (1) Previously, I had fillchar'd the static arrays with zeros because > they are sparse-ish. Looks like dynamic arrays are automagically > filled with zeros. Is this true/permanent? Yes. > (2) There is no way, I supposed, to switch the array indexes to start > at 1 is there? No, there is unfortunately no way to do this. Jonas

Reply by email

Alan Mead
to Cox, Stuart TRAN:EX

Yes, this is a good idea. I think it thwarts length() and low() but since I'm using two dimensional arrays, these aren't helpful...

I'm not a fluent OOP programmer, but I'm already using a record to record the real rows and columns, matrix name, etc. so I think I'm going to wrap these open arrays in an object so that I can supply replacements for these and other methods and it would be easy to hide this wrinkle inside the object.

-Alan

Show quoted text 50 lines
Would not allocating the dynamic arrays a single element greater in size not permit you to address their elements the way you'd like. I.e.: for a five element array, allocate size 6 and get [0..5] and then use only [1..5]? Just pretend that the [0] position doesn't exist. Of Course, you'd have to be careful with low(x) as the index starting spot. If this is too easy what am I missing? Stu -----Original Message----- From: On Behalf Of Jonas Maebe Sent: Wednesday, July 28, 2004 12:00 PM To: Subject: Re: [fpc-pascal]Two simple dynamic arrays questions On 28 jul 2004, at 19:48, Alan Mead wrote: > (1) Previously, I had fillchar'd the static arrays with zeros because > they are sparse-ish. Looks like dynamic arrays are automagically > filled with zeros. Is this true/permanent? Yes. > (2) There is no way, I supposed, to switch the array indexes to start > at 1 is there? No, there is unfortunately no way to do this. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email