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 5963757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:18:38+00:00 2026-05-22T19:18:38+00:00

I have 2 or more dynamic string array that fill with some huge data

  • 0

I have 2 or more dynamic string array that fill with some huge data , i want to merge this 2 array to one array , i know i can do it with a for loop like this :

var
  Arr1, Arr2, MergedArr: Array of string;
  I: Integer;
begin
  // Arr1:= 5000000 records
  // Arr2:= 5000000 records

  // Fill MergedArr by Arr1
  MergedArr:= Arr1;

  // Set length of MergedArr to length of ( Arra1 + Arr2 )+ 2
  SetLength(MergedArr, High(Arr1)+ High(Arr2)+2);

  // Add Arr2 to MergedArr
  for I := Low(Arr2)+1 to High(Arr2)+1 do
    MergedArr[High(Arr1)+ i]:= Arr2[i-1];
end;

but it is slow on huge data , is there faster way like copy array memory data ?

  • 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-22T19:18:39+00:00Added an answer on May 22, 2026 at 7:18 pm

    You can use built-in Move function which moves a block of memory to another location. Parameters are source and target memory blocks and size of data to be moved.

    Because you are copying strings, source arrays must be destroyed after the merging by filling them with zeroes. Otherwise refcounts for strings will be all wrong causing havoc and destruction later in the program.

    var
      Arr1, Arr2, MergedArr: Array of string;
      I: Integer;
    begin
      SetLength(Arr1, 5000000);
      for I := Low(Arr1) to High(Arr1) do
        Arr1[I] := IntToStr(I);
    
      SetLength(Arr2, 5000000);
      for I := Low(Arr2) to High(Arr2) do
        Arr2[I] := IntToStr(I);
    
      // Set length of MergedArr to length of ( Arra1 + Arr2 )+ 2
      SetLength(MergedArr, High(Arr1)+ High(Arr2)+2);
    
      // Add Arr1 to MergedArr
      Move(Arr1[Low(Arr1)], MergedArr[Low(MergedArr)], Length(Arr1)*SizeOf(Arr1[0]));
    
      // Add Arr2 to MergedArr
      Move(Arr2[Low(Arr2)], MergedArr[High(Arr1)+1], Length(Arr2)*SizeOf(Arr2[0]));
    
      // Cleanup Arr1 and Arr2 without touching string refcount.
      FillChar(Arr1[Low(Arr1)], Length(Arr1)*SizeOf(Arr1[0]), 0);
      FillChar(Arr2[Low(Arr2)], Length(Arr2)*SizeOf(Arr2[0]), 0);
    
      // Test
      for I := Low(Arr1) to High(Arr1) do begin
        Assert(MergedArr[I] = IntToStr(I));
        Assert(MergedArr[I] = MergedArr[Length(Arr1) + I]);
      end;
    
      // Clear the array to see if something is wrong with refcounts
      for I := Low(MergedArr) to High(MergedArr) do
        MergedArr[I] := '';
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dynamic form that I've written in rails. I want to be
I have a page to which I am adding a dynamic UpdatePanel with more
I have this table where I can generate dynamic rows (which has input <type=text
I have two divs floated left so that they appear next to each other.
I'm aware that I could use something called std::vector , but I'm afraid it's
Of. I have found plenty of resources on converting specific url strings (domain.com/?hello=world to
I'm working on creating a dashboard. I have started to refactor the application so
Let's say I have a List of strings. In addition to the list, I
How can I unlock or delete a file that is in use, so that

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.