Copying a 2D array to another one

Hello,

I have an 2D array like this MyArray:array of array of boolean;

what is the fastest way to copy all the datas from this array to another 
  2D array of same size ?


Thanks

John
0
John
9/10/2008 10:39:06 AM
embarcadero.delphi.win32 2183 articles. 0 followers. Follow

11 Replies
581 Views

Similar Articles

[PageSpeed] 1

A Move with a SizeOf ?

DH
0
David
9/10/2008 11:21:45 AM
how do you use it with a 2D array ?
0
John
9/10/2008 11:38:49 AM
for _each := Low(source) to High(source)
    do move(source[_each], _target[_each], Length(source)*sizeof(boolean));

That only works if the array sizes are the same and if the arrays are 
already allocated !

DH
0
David
9/10/2008 11:45:06 AM
John Terry wrote:

> Hello,
> 
> I have an 2D array like this MyArray:array of array of boolean;
> 
> what is the fastest way to copy all the datas from this array to
> another   2D array of same size ?

  SetLength(SecondArray, Length(MyArray));
  for I := 0 to High(MyArray) do
    SecondArray[I] := Copy(MyArray[I]);
    
an array of array of Boolean is in fact an "array of (array of
Boolean)", i.e. a single dimensional array of array pointers. So you
can copy it by creating another array of the same type and size
(length(MyArray)) and the copying the single arrays of Boolean one by
one.

-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"This isn't right, this isn't even wrong."
 -- Wolfgang Pauli (1900-1958), upon reading a young physicist's 
    paper
0
Rudy
9/10/2008 11:55:29 AM
David HAROUCHE wrote:

> A Move with a SizeOf ?

No way. Dynamic 2D arrays are not flat, so you can't use one single
Move. And SizeOf(MyArray) = 4, since it is only a pointer.

-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"Am I lightheaded because I'm not dead or because I'm still 
 alive?" -- Heidi Sandige.
0
Rudy
9/10/2008 11:55:39 AM
David HAROUCHE wrote:

> for _each := Low(source) to High(source)
>    do move(source[_each], _target[_each],
> Length(source)*sizeof(boolean));
> 
> That only works if the array sizes are the same and if the arrays are
> already allocated !

Using Copy, like I showed, is much better. Copy will handle all the
allocations and the moves.
-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"Heav'n hath no rage like love to hatred turn'd, Nor Hell a fury, 
 like a woman scorn'd."
 -- William Congreve (1670-1729)
0
Rudy
9/10/2008 11:56:39 AM
Copy does two jobs, and Move only its own, isnt it ?

DH
0
David
9/10/2008 2:50:41 PM
David HAROUCHE wrote:

> Copy does two jobs, and Move only its own, isnt it ?
> 
> DH

Copy does everything required, including updating reference counts,
etc. (which Move does not). But only for one-dimensional arrays, so
every higher level of a multidimensional dynamic array must be done
manually.

-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"machine. Unexpectedly, I'd invented a time "
 -- Alan Moor
0
Rudy
9/10/2008 4:01:06 PM
Could we consider Move as ScanLines and Copy as Pixels ?

DH
0
David
9/10/2008 5:08:26 PM
David HAROUCHE wrote:

> Could we consider Move as ScanLines and Copy as Pixels ?

We should consider Move as a low level totally unintelligent function
that should be avoided whenever possible, while Copy is a much higher
level function, taking care of everything necessary. Using Copy is MUCH
less error prone than using Move.

-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"Should array indices start at 0 or 1? My compromise of 0.5 was
 rejected without, I thought, proper consideration."
 -- Stan Kelly-Bootle
0
Rudy
9/10/2008 7:37:24 PM
Thks

DH
0
David
9/10/2008 8:50:30 PM
Reply:

Similar Artilces:

How to Copy Different Length Arrays To Another One? [Edit]
I have a routine that uses elements of different length arrays. Let's say: {code} List1 : Array[1..1] Of String = ('A'); List2 : Array[1..4] Of String = ('B', 'C', D', 'E'); List3 : Array[1..3] Of String = ('F', 'G', H'); {code} I wish I could simply copy the content of each array to a common one according to my needs, instead of having to write different procedures for each List1, List2 and List3. Something like "*If xxx then List = List1 else List = List2*". And then use: {code} begin for i := 1 to Length(List...

Copying Sybase users from one database to another
TEST ONLY - SYBASE ASA703 WIN32. Hi all, I have two systems both the same. I want to copy the Sybase users from one system to another. I know I could unload the schema from the one database and strip out everything but the create user ids. But could I do it through a CURSOR and Proxy tables. So far I can apart from the password field from sysuserperm as it is encrypted. Is there any way of solving this problem given the following example: IF EXISTS(Select Proc_name from sysprocedure where Proc_name = 'SYBASE_USERS_COPY_PROC') THEN Drop PROCEDURE dba.SYBASE_USERS_COPY_...

Copy an array to another array by Pointer
Hi All, I have a lot of arrays like SomeArray1: Array[1..NumberOfElements1] of String = ('element1', 'element2', 'element3', 'element4' ....... SomeArray2: Array[1..NumberOfElements2] of String = ('element1', 'element2', 'element3', 'element4' ....... SomeArray3: Array[1..NumberOfElements3] of String = ('element1', 'element2', 'element3', 'element4' ....... SomeArray4: Array[1..NumberOfElements4] of String = ('element1', 'element2', 'element3', 'element4&...

copy 3D array to 2D array
hi, i am trying to copy a three dimensional array to a two dimentional one this: @AoA = ( [2, 3], [4, 5, 7], [0] ); to this @A = qw(2 3 4 5 7 0); i know the answer is staring at me in perldoc perldsc but i cant see it! thanks rob On Tue, Feb 10, 2009 at 11:13, Rob Canning <robcanning@eircom.net> wrote: > hi, > > i am trying to copy a three dimensional array to a two dimentional one > > this: > > @AoA = ( [2, 3], [4, 5, 7], [0] ); > > to this > > @A = qw(2 3 4 5 7 0); > > i know the answer is staring at me in pe...

Delphi XE6 FireDAC SQLite copy a table from one database to another
How do I copy a single table from one SQLite database to another? Is there a simple command to do this? Thanks! > How do I copy a single table from one SQLite database to another? Is there a simple command to do this? Thanks! You should use ATTACH command. For example: {code} ATTACH 'c:\secondDB.sdb' AS sec; INSERT INTO SomeTab SELECT * FROM sec.SomeTab; {code} -- With best regards, Dmitry Arefiev / FireDAC Architect Thanks! > {quote:title=Dmitry Arefiev wrote:}{quote} > > How do I copy a single table from one SQLite database to another? Is there a...

how to copy one table from one database to another on different servers?
 Hello. I need to copy all of the rows in a table from a database on one server, to another existing table of the same name in a different database on a different server.  I'm trying to use a SELECT INTO statement.  Any idea how to do this?I've tried SELECT          *   INTO                  DestinationServer.dbo.DestinationDB.DestinationTableFROM             &nb...

Help with copying data from one gridview to another gridview on another page
Hello,I have a page, frmJobListings.aspx, with a data grid that is populated with data from a table called, tblJobPostings.  I would like to copy all rows of data from three of the columns, JobRefNum, JobRequirements, and JobTitle on the page and populate a datagrid on another page called, frmJobDetails when I click on a button called, btnJobDetailBuilder. Problem: When I click on the btnJobDetailBuilder the page frmJobDetails opens but does not display the datagrid, errors, or any information.  I know that I need to do a data bind, but not sure if or how to databind to the 'Re...

How can I copy "Schedule Task" from one server to another one?
On one of my NW6 server I scheduled a lot of maintenance tasks (i.e. down and restart for antivirus before and after backup-job...). I have 4 servers NW6 and I would like to copy this tasks from one to another... Is it possible? How can I do this? Thanks. Davide. davide.pignedoli@metasystem.it, The Scheduled Tasks commands are stored in the server registry, (c:\nwserver\servcfg.*). Though you could manually edit the registry, through NetWare Remote Manager or "CDBE EDIT ON", there's no way to copy single items out of the registry. Copying the whole server regist...

Copying information from One table to Another from 2 different databases on one server
Can I copy accross databases e.g.: In MS SQL I can: Insert into Database2..customer select * from Database1..customer Thanks in Advance Yes you can. The syntax in Sybase is same. The syntax is the same if you are on ASE. ASA does not support that syntax. You need to use a Proxy table instead. -- Jim Egan [TeamSybase] Houston, TX http://www.eganomics.com Sybase Developers Network http://sdn.sybase.com/sdn/mec/mec_home.stm ...

Copy one database to another
Hi      I want to Copy one database to another in MSAcess i am using asp.net, C#  and copy all tables from one database to another.     Regards Neha Probably the easiest way is to simply use the classes in the System.IO namespace to copy the mdb file.  If you only want the structure, and not the data, iterate the tables in the copy database and DELETE * from them.  Have a look at Jet Replication Objects for compacting and repairing the copy database afterwards: http://www.codeproject.com/KB/database/mdbcompact_latebind.aspx Regards Mi...

copying one object to another...
Hi,I have a namevaluecollection object which is being used in 2 different threads.One thread updates the values and the other reads it.In reading thread I want to read the namevaluecollection in a local object and then use that local object to read and then display it so that the reading thread uses the namevaluecollection object for the least amount of time. How can I copy the shared namevaluecollection to a local object such that after copying it to the local object, the shared namevaluecollection is set free for the other thread to use...I believe doing this does'nt free the ShareName...

Copying one DataTable to another
This is what I've tried and it doesn't work:DataTable dtNew = new DataTable("New");dtNew = dtOldThanks in advance for any help in pointing me in the right direction to do this   DataTable dtNew = dtOld.Copy();Steve Wellens My blog...

How to copy from one DataSet to another
 So i've been pulling my hair out for the past couple of hours trying to figure out how to achieve this and i finally get my algorithm down and but i can't figure out how to insert data into a new dataset. So here's the situation. I'm getting a dataset from my DB that only return one table. Then i only need the last couple of tuples from the dataset, so i figure out the index position of where to start from. I then want to start from that index position and copy the remaining data into a new dataset. Every attempt to copy, i get some sort of error like "that row alr...

Copying one datagrid to another
Hi All,Can anybody pls let me know how to copy rows of a datagrid control to another datagrid based on a condition in the first datagrid (WebApplication)Example:DataGrid1Column1 Column2 column3abc          xyz          chkbox(checked)def          pqr          chkbox(not checked)test         exam        &nbs...

Web resources about - Copying a 2D array to another one - embarcadero.delphi.win32

Private copying levy - Wikipedia, the free encyclopedia
A private copying levy (also known as blank media tax or levy ) is a government -mandated scheme in which a special tax or levy (additional to ...

Zynga CEO Dispels Facebook Game Copying Accusations
... they are like the crew mechanic in our games. They give you a new way to interact with your friends. Zynga was also accused last week of copying ...

Showing Apple employee #8 some of my artifacts. He remembers manually copying the Star Wars cassettes ...
jurvetson posted a photo: He has a rig that fed eight recoding tape drives from one master, and he would manually copy eight tapes at a time ...

The Secret Pattern That Stops You Copying Bank Notes - YouTube
http://tomscott.com - @tomscott - There's a hidden pattern on banknotes, all around the world, that means photocopiers refuse to copy them.

CSAIL fixes software bugs automatically, in any language, by copying from safer applications
A new system can repair bugs in software using smart processing that imports functionality from other programs, all without access to source ...

Australia risks copying US 'ag-gag' laws to turn animal activists into terrorists
When Amy Meyer saw a sick cow being pushed by a bulldozer outside a slaughterhouse, she did what any of us would in this age of iPhones and Instagram ...

Hardware vendors sue Dutch government over copyright levies - regulation, legal, Dutch Home Copying Foundation ...
... on hard disks, smartphones, tablets and MP3 players that are meant to compensate the music and movie industries for losses caused by home copying. ...

Grace Jones slams Lady Gaga for copying her, describes her as soulless - The Courier-Mail Search Search ...
GRACE Jones has slammed Lady Gaga in a new interview, saying she didn’t “feel a soul” when she met the controversial pop star.

Iran claims to be copying US drone
CTV.ca Iran claims to be copying US drone Herald Sun AN IRANIAN military commander said the country is building a copy of a US spy drone captured ...

Ex-cop pleads guilty to copying sex video
A former officer has pleaded guilty to copying a private sex video he found on the mobile phone of a victim who came to police for help last ...

Resources last updated: 1/21/2016 7:16:38 AM