Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
indy tidtcpclient threading issue 8 63
delphi exception 7 61
how can i search if string exist in array ? 3 49
PHP preg_replace code convert to Delphi 14 32
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

21 Experts available now in Live!

Get 1:1 Help Now