Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-04-21
2
Medium Priority
?
150 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

926 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