Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
How can I save a multidimensional dynamic array?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Manuel Meyer  
View profile  
 More options Aug 10 2001, 1:13 pm
Newsgroups: borland.public.delphi.students
From: "Manuel Meyer" <manuel.me...@debitel.net>
Date: Fri, 10 Aug 2001 19:02:01 +0200
Local: Fri, Aug 10 2001 1:02 pm
Subject: How can I save a multidimensional dynamic array?
Hello!

I am working with a multidimensional dynamic array that
stores double-values.

To save the data on my harddisc, I want to write it into
a stream-object (TFileStream). What is the best way to
do that?

The TFileStream-class has read- and write-methods. Can
I somehow use my array as an argument for these methods?

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gary Williams  
View profile  
 More options Aug 10 2001, 3:59 pm
Newsgroups: borland.public.delphi.students
From: "Gary Williams" <gwtemp2...@yahoo.com>
Date: Fri, 10 Aug 2001 14:47:19 -0500
Local: Fri, Aug 10 2001 3:47 pm
Subject: Re: How can I save a multidimensional dynamic array?
"Manuel Meyer" <manuel.me...@debitel.net> wrote in message

news:3b7414db_2@dnews...

> I am working with a multidimensional dynamic array that
> stores double-values.

> To save the data on my harddisc, I want to write it into
> a stream-object (TFileStream). What is the best way to
> do that?

> The TFileStream-class has read- and write-methods. Can
> I somehow use my array as an argument for these methods?

Multidimensional dynamic arrays may point to noncontiguous memory blocks.
You will need to write custom procedures to read and write your array.  You
will also need to save the size of each dimension before the actual data.

If your array has a fixed number of dimensions then you can get away with
using nested for-loops.  The innermost loop can persist an entire row of
values with one call to Stream.Write.

Please note that the following code is off the top of my head just to get
you started.  It may not compile.

type
  TMyArray = array of array of array of array of Double;

procedure WriteArrayToStream(const MyArray: TMyArray;
                             const Stream: TStream);

var
  A, B, C, N: LongInt;

begin
  N := Length(MyArray);
  Stream.Write(N, SizeOf(N));

  for A := 0 to High(MyArray) do
  begin
    N := Length(MyArray[A]);
    Stream.Write(N, SizeOf(N));

    for B := 0 High(MyArray[A]) do
    begin
      N := Length(MyArray[A, B]);
      Stream.Write(N, SizeOf(N));

      for C := 0 to High(MyArray[A, B]) do
      begin
        N := Length(MyArray[A, B, C]);
        Stream.Write(N, SizeOf(N));

        Stream.Write(@MyArray[A, B, C, 0], N * SizeOf(Double));
      end;
    end;
  end;
end;

The loading mechanism would have a call to SetLength at each point where
length information was saved.

procedure ReadArrayFromStream(out MyArray: TMyArray;
                              const Stream: TStream);

var
  A, B, C, NA, NB, NC, ND: LongInt;

begin
  Stream.Position := 0;

  Stream.Read(NA, SizeOf(NA));
  SetLength(MyArray, NA);

  for A := 0 to (NA - 1) do
  begin
    Stream.Read(NB, SizeOf(NB));
    SetLength(MyArray[A], NB);

    for B := 0 to (NB - 1) do
    begin
      Stream.Read(NC, SizeOf(NC));
      SetLength(MyArray[A, B], NC);

      for C := 0 to (NC - 1)) do
      begin
        Stream.Read(ND, SizeOf(ND));
        SetLength(MyArray[A, B, C], ND);

        Stream.Read(@MyArray[A, B, C, 0], ND * SizeOf(Double));
      end;
    end;
  end;
end;

-Gary


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »