Solved

how do i get the total amount of bytes in which a dynamic array is stored?

Posted on 2002-04-21
2
142 Views
Last Modified: 2010-04-04
In other words I would like something like Length(dinarray) to return the length in bytes of the array.
I need this to use it with BlockRead. I did something like this, but it seems that it doesn't work.

var  maparray: array of array of byte;

procedure TForm1.Button3Click(Sender: TObject);
var resd : integer;
begin
  setlength(maparray, 20, 15);
  resd := length(maparray) * length(maparray[0]) * sizeof(maparray[0][0]);
  showmessage(inttostr(resd));
end;


I use BlockRead this way:
      BlockRead(F, maparray[0][0], Length(maparray) * Length(maparray[0]) * sizeof(maparray));

thanks in advance,
paul.
0
Comment
Question by:pin_plunder
2 Comments
 
LVL 1

Accepted Solution

by:
MBo earned 50 total points
ID: 6958915
Your formula:
resd := length(maparray) * length(maparray[0]) * sizeof(maparray[0][0]);
is correct, but it is not guaranteed that multidimensional dynamic array is situated in continuos block of memory.
Each first-level array is continuos, but it contains reference counter and length (integers) before the first element a[0].

So you need blockread every first-level array one-by-one.

For the best occasion (when all arrays follow each other) there are extra bytes (8 or 12 bytes for each array included)
Sorry for my poor English
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9003890
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from MBo

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now