If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Copy/Duplicate Arrays

I need to replicate an array, but do not want the new array to reference =
the
original array's memory location. In other words, I need a completely
separate, exact copy of the original array so that I can manipulate its
elements without impacting the original array elements.

I have tried Array.Copy, but that seems to just point the new array's
elements to the memory location of the original array's elements. Is =
there a
way to create a clean, new copy of an existing array?

Copy/Duplicate Arrays

Greetings,

I need to replicate an array, but do not want the new array to reference the
original array's memory location. In other words, I need a completely
separate, exact copy of the original array so that I can manipulate its
elements without impacting the original array elements.

I have tried Array.Copy, but that seems to just point the new array's
elements to the memory location of the original array's elements. Is there a
way to create a clean, new copy of an existing array?

I need to replicate an array, but do not want the new array to reference the
original array's memory location. In other words, I need a completely
separate, exact copy of the original array so that I can manipulate its
elements without impacting the original array elements.

I have tried Array.Copy, but that seems to just point the new array's
elements to the memory location of the original array's elements. Is there a
way to create a clean, new copy of an existing array?

Re: Copy/Duplicate Arrays

No it doesn't, it clones the array, so perhaps your problem is that you have
an array of references, in which case you have a completely new array of
references but they point to the same objects?
Perhaps some more information would help, like what is it an array of?

Cheers,
iGadget

"David Gaines" <dgaines@atlanticappraisal.com> wrote in message
news:3dad78c0$1@tnews.web.devx.com...
> Thanks for the response Steve, but that doesn't work.
>
> Clone apparently also just points the array2 to the array1 memory.
>
> Thanks again anyway,
> Dave
>
> "Steve Cochran" <scochran@chattanooga.net> wrote in message
> news:3dad5cf5$1@tnews.web.devx.com...
> try
>
> array2=array1.clone
>
> steve
>
> "David Gaines" <dgaines@atlanticappraisal.com> wrote in message
> news:3dad5c3c$1@tnews.web.devx.com...
> Greetings,
>
> I need to replicate an array, but do not want the new array to reference
the
> original array's memory location. In other words, I need a completely
> separate, exact copy of the original array so that I can manipulate its
> elements without impacting the original array elements.
>
> I have tried Array.Copy, but that seems to just point the new array's
> elements to the memory location of the original array's elements. Is there
a
> way to create a clean, new copy of an existing array?
>
> Thanks,
> Dave Gaines
>
> --
> Regards,
> Dave Gaines
> dgaines@atlanticappraisal.com
>
> Associate Appraiser
> Atlantic Appraisal Company, Inc.
> 2355 Huguenard Drive, Suite 202
> Lexington, KY 40503
> (859) 273-2060, x238
>
>
>

I need to replicate an array, but do not want the new array to reference =
the
original array's memory location. In other words, I need a completely
separate, exact copy of the original array so that I can manipulate its
elements without impacting the original array elements.

I have tried Array.Copy, but that seems to just point the new array's
elements to the memory location of the original array's elements. Is =
there a
way to create a clean, new copy of an existing array?

Re: Copy/Duplicate Arrays

Thanks to all for the suggestions; here is some more information. I've declared an array of structures as shown below. I am now trying to create a clean copy of this array, also as excerpted below.

BTW, to make it work, I have created a work around where I step through every element of my new array and just set it equal to the value in the old array. It works as it is, but I thought there might be a more "correct" method. I have excerpted relevant portions of my code below.

Structure Individual
Public Number As Integer
Public Chromosone() As Integer
Public Value As Decimal
Public Fitness As Decimal
Public Parent1, Parent2, XSite1, XSite2 As Integer
End Structure

Public GenePool() As Individual

Dim TempPop As Individual()

ReDim TempPop(UBound(GenePool))

'TempPop = GenePool.Clone

'Array.Copy(GenePool, TempPop, UBound(GenePool) + 1)

For i = 0 To UBound(TempPop)

ReDim TempPop(i).Chromosone(UBound(GenePool(i).Chromosone))

For j = 0 To UBound(TempPop(i).Chromosone)

TempPop(i).Chromosone(j) = GenePool(i).Chromosone(j)

TempPop(i).Number = GenePool(i).Number

Next

Next

"iGadget" <iGadget_@hotmail.com> wrote in message news:3dad8323$1@tnews.web.devx.com...
> No it doesn't, it clones the array, so perhaps your problem is that you have
> an array of references, in which case you have a completely new array of
> references but they point to the same objects?
> Perhaps some more information would help, like what is it an array of?
>
> Cheers,
> iGadget
>
> "David Gaines" <dgaines@atlanticappraisal.com> wrote in message
> news:3dad78c0$1@tnews.web.devx.com...
> > Thanks for the response Steve, but that doesn't work.
> >
> > Clone apparently also just points the array2 to the array1 memory.
> >
> > Thanks again anyway,
> > Dave
> >
> > "Steve Cochran" <scochran@chattanooga.net> wrote in message
> > news:3dad5cf5$1@tnews.web.devx.com...
> > try
> >
> > array2=array1.clone
> >
> > steve
> >
> > "David Gaines" <dgaines@atlanticappraisal.com> wrote in message
> > news:3dad5c3c$1@tnews.web.devx.com...
> > Greetings,
> >
> > I need to replicate an array, but do not want the new array to reference
> the
> > original array's memory location. In other words, I need a completely
> > separate, exact copy of the original array so that I can manipulate its
> > elements without impacting the original array elements.
> >
> > I have tried Array.Copy, but that seems to just point the new array's
> > elements to the memory location of the original array's elements. Is there
> a
> > way to create a clean, new copy of an existing array?
> >
> > Thanks,
> > Dave Gaines
> >
> > --
> > Regards,
> > Dave Gaines
> > dgaines@atlanticappraisal.com
> >
> > Associate Appraiser
> > Atlantic Appraisal Company, Inc.
> > 2355 Huguenard Drive, Suite 202
> > Lexington, KY 40503
> > (859) 273-2060, x238
> >
> >
> >
>
>

Re: Copy/Duplicate Arrays

"David Gaines" <dgaines@atlanticappraisal.com> wrote:
>Greetings,
>
>I need to replicate an array, but do not want the new array to reference
the
>original array's memory location. In other words, I need a completely
>separate, exact copy of the original array so that I can manipulate its
>elements without impacting the original array elements.
>
>I have tried Array.Copy, but that seems to just point the new array's
>elements to the memory location of the original array's elements. Is there
a
>way to create a clean, new copy of an existing array?
>
>Thanks,
>Dave Gaines
>
>--
>Regards,
>Dave Gaines
>dgaines@atlanticappraisal.com
>
>Associate Appraiser
>Atlantic Appraisal Company, Inc.
>2355 Huguenard Drive, Suite 202
>Lexington, KY 40503
>(859) 273-2060, x238
>
>
Hi David,

From your code it is apparent that you have not really understood what iGadget
was saying which is indeed correct.

Array.Clone creates a 'shallow' copy of the array. ArrayInstance.CopyTo will
perform a shallow copy to the nominated predeclared, predimensioned array.
Array.Copy will perform a shallow copy between two arrays even when ArraySource
and ArrayDestination are the same array - great for moving elements inside
an array.

Your code could be rewritten as follows:

Structure Individual
Public Number As Integer
Public Chromosone() As Integer
Public Value As Decimal
Public Fitness As Decimal
Public Parent1, Parent2, XSite1, XSite2 As Integer
End Structure

Re: Copy/Duplicate Arrays

You spelled Chromosome wrong. <G>

steve

"David Gaines" <dgaines@atlanticappraisal.com> wrote in message news:3dadce8e$1@tnews.web.devx.com...
Thanks to all for the suggestions; here is some more information. I've declared an array of structures as shown below. I am now trying to create a clean copy of this array, also as excerpted below.

BTW, to make it work, I have created a work around where I step through every element of my new array and just set it equal to the value in the old array. It works as it is, but I thought there might be a more "correct" method. I have excerpted relevant portions of my code below.

Structure Individual
Public Number As Integer
Public Chromosone() As Integer
Public Value As Decimal
Public Fitness As Decimal
Public Parent1, Parent2, XSite1, XSite2 As Integer
End Structure

Public GenePool() As Individual

Dim TempPop As Individual()

ReDim TempPop(UBound(GenePool))

'TempPop = GenePool.Clone

'Array.Copy(GenePool, TempPop, UBound(GenePool) + 1)

For i = 0 To UBound(TempPop)

ReDim TempPop(i).Chromosone(UBound(GenePool(i).Chromosone))

For j = 0 To UBound(TempPop(i).Chromosone)

TempPop(i).Chromosone(j) = GenePool(i).Chromosone(j)

TempPop(i).Number = GenePool(i).Number

Next

Next

"iGadget" <iGadget_@hotmail.com> wrote in message news:3dad8323$1@tnews.web.devx.com...
> No it doesn't, it clones the array, so perhaps your problem is that you have
> an array of references, in which case you have a completely new array of
> references but they point to the same objects?
> Perhaps some more information would help, like what is it an array of?
>
> Cheers,
> iGadget
>
> "David Gaines" <dgaines@atlanticappraisal.com> wrote in message
> news:3dad78c0$1@tnews.web.devx.com...
> > Thanks for the response Steve, but that doesn't work.
> >
> > Clone apparently also just points the array2 to the array1 memory.
> >
> > Thanks again anyway,
> > Dave
> >
> > "Steve Cochran" <scochran@chattanooga.net> wrote in message
> > news:3dad5cf5$1@tnews.web.devx.com...
> > try
> >
> > array2=array1.clone
> >
> > steve
> >
> > "David Gaines" <dgaines@atlanticappraisal.com> wrote in message
> > news:3dad5c3c$1@tnews.web.devx.com...
> > Greetings,
> >
> > I need to replicate an array, but do not want the new array to reference
> the
> > original array's memory location. In other words, I need a completely
> > separate, exact copy of the original array so that I can manipulate its
> > elements without impacting the original array elements.
> >
> > I have tried Array.Copy, but that seems to just point the new array's
> > elements to the memory location of the original array's elements. Is there
> a
> > way to create a clean, new copy of an existing array?
> >
> > Thanks,
> > Dave Gaines
> >
> > --
> > Regards,
> > Dave Gaines
> > dgaines@atlanticappraisal.com
> >
> > Associate Appraiser
> > Atlantic Appraisal Company, Inc.
> > 2355 Huguenard Drive, Suite 202
> > Lexington, KY 40503
> > (859) 273-2060, x238
> >
> >
> >
>
>