Solved

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

Posted on 2002-04-21
2
144 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 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

10 Experts available now in Live!

Get 1:1 Help Now