Solved

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

Posted on 2002-04-21
2
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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