Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3876968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:26:35+00:00 2026-05-19T22:26:35+00:00

I have an algorithm where I create two bi-dimensional arrays like this: TYPE TPtrMatrixLine

  • 0

I have an algorithm where I create two bi-dimensional arrays like this:

  TYPE
   TPtrMatrixLine = array of byte;
   TCurMatrixLine = array of integer;
   TPtrMatrix     = array of TPtrMatrixLine;                                    
   TCurMatrix     = array of TCurMatrixLine;  


  function x
  var  
     PtrsMX: TPtrMatrix;
     CurMx : TCurMatrix;         
  begin 
   { Try to allocate RAM }
   SetLength(PtrsMX, RowNr+1, ColNr+1);                              
   SetLength(CurMx , RowNr+1, ColNr+1);
   for all rows do 
    for all cols do 
     FillMatrixWithData; <------- CPU intensive task. It could take up to 10-20 min
  end;

The two matrices have always the same dimension.
Usually there are only 2000 lines and 2000 columns in the matrix but sometimes it can go as high as 25000×6000 so for both matrices I need something like 146.5 + 586.2 = 732.8MB of RAM.
The problem is that the two blocks need to be contiguous so in most cases, even if 500-600MB of free RAM doesn’t seem much on a modern computer, I run out of RAM.

The algorithm fills the cells of the array with data based on the neighbors of that cell. The operations are just additions and subtractions.

The TCurMatrixLine is the one that takes a lot or RAM since it uses integers to store data. Unfortunately, values stored may have sign so I cannot use Word instead of integers. SmallInt is too small (my values are bigger than SmallInt, but smaller than Word). I hope that if there is any other way to implement this, it needs not to add a lot of overhead, since processing a matrix with so many lines/column already takes a lot of time. In other words I hope that decreasing memory requirements will not increase processing time.

Any idea how to decrease the memory requirements?
[I use Delphi 7]


Update
Somebody suggested that each row of my array should be an independent uni-dimensional array.
I create as many rows (arrays) as I need and store them in TList. Sound very good. Obviously there will be no problem allocation such small memory blocks. But I am afraid it will have a gigantic impact on speed. I use now

TCurMatrixLine = array of integer;                                   
TCurMatrix     = array of TCurMatrixLine; 

because it is faster than TCurMatrix= array of array of integer (because of the way data is placed in memory). So, breaking the array in independent lines may affect the speed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:26:36+00:00Added an answer on May 19, 2026 at 10:26 pm

    The suggestion of using a signed 2 byte integer will greatly aid you.

    Another useful tactic is to mark your exe as being LARGE_ADDRESS_AWARE by adding {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} to your .dpr file. This will only help if you are running on 64 bit Windows and will increase your address space from 2GB to 4GB.

    It may not work on Delphi 7 (I seem to recall you are using D7) and you must be using FastMM since the old Borland memory manager isn’t compatible with large address space. If $SetPEFlags isn’t available you can still mark the exe with EDITBIN.

    If you still encounter difficulties then yet another trick is to do allocate smaller sub-blocks of memory and use a wrapper class to handle mapping indices to the appropriate sub-block and offset within. You can use a default index property to make this transparent to the calling code.

    Naturally a block allocated approach like this does incur some processing overhead but it’s your best bet if you are having troubles with getting contiguous blocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two bitmaps, produced by different variations of an algorithm. I'd like to
I have a two part question Best-Practice I have an algorithm that performs some
I have a language-agnostic question about an algorithm. This comes from a (probably simple)
I have a snippet to create a 'Like' button for our news site: <iframe
I have an algorithm that generates strings based on a list of input words.
I have a recursive algorithm which steps through a string, character by character, and
Does anyone have a decent algorithm for calculating axis minima and maxima? When creating
Does anyone have a good algorithm for taking an ordered list of integers, i.e.:
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Does anyone have a trusted Proper Case or PCase algorithm (similar to a UCase

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.