This is probably a very silly, and simple question. If I'm coding in
CLI, and I want to copy an array to an array, not a deep copy, just
something of the nature arr1 = arr2, what is going on?
I assumed the address of the first element is getting copied, so i
essentially have two handles to the same memory. And changes in one
would be reflected in the other.
But what if I have something like this
public value struct MyStruct
{
Int32 MyNumber;
};
array<MyStruct> ^ arr1 = gcnew array<MyStruct( 10);
//We fill the array with 10 MyStruct
array<MyStruct> ^ arr2 = arr1;
Now what do we have here? since it's a value struct, did we
essentially do a deep copy? 2 1389
On 2007-09-10 21:11, DaTurk wrote:
This is probably a very silly, and simple question. If I'm coding in
CLI, and I want to copy an array to an array, not a deep copy, just
something of the nature arr1 = arr2, what is going on?
If you are coding in C++/CLI you are asking in the wrong group. This
group is for discussing C++ (and while C++/CLI might have a name and
syntax similar to C++ they are two very different things). I would
suggest you ask your question in either one of the microsoft.publi c.*
groups, microsoft.publi c.dotnet.langua ges.vc is probably the one you
want. Another good place to ask is forums.microsof t.com
--
Erik Wikström
"DaTurk" <mm******@hotma il.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
This is probably a very silly, and simple question. If I'm coding in
CLI, and I want to copy an array to an array, not a deep copy, just
something of the nature arr1 = arr2, what is going on?
I assumed the address of the first element is getting copied, so i
essentially have two handles to the same memory. And changes in one
would be reflected in the other.
But what if I have something like this
public value struct MyStruct
{
Int32 MyNumber;
};
array<MyStruct> ^ arr1 = gcnew array<MyStruct( 10);
//We fill the array with 10 MyStruct
array<MyStruct> ^ arr2 = arr1;
Now what do we have here? since it's a value struct, did we
essentially do a deep copy?
Ignoring hte fact that this isn't C++ code but something else (C# maybe?)
and presuming ^ is some type of pointer...
If this code was:
public value struct MyStruct
{
Int32 MyNumber;
};
MyStruct* arr1 = new MyStruct[10];
//We fill the array with 10 MyStruct
MyStruct* arr2 = new MyStruct[10];
You would want to iterate over the array copying elements. The manual
method is:
for ( size_t i = 0; i < 10; ++i )
arr2[i] = arr1[i];
This is a very common task, however, so TPTB added it to the stl with
std::copy
std::copy( arr1.begin(), arr1.end(), std::inserter(a rr2, arr2.end()) );
The syntax for the 3rd parameter of std::copy here may be wrong, but it
should work.
Other than that, ask in a newsgroup related to your language, whatever it
is. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matteo Settenvini |
last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using
g++ 3.3.x.
I had been taught that an array isn't a lot different from a pointer
(in fact you can use the pointer arithmetics to "browse" it). So I
expected that when I run this program, I get both c1.A and c2.A
pointing to the same address, and changing c1.A means that also...
|
by: anonymous |
last post by:
Hi folks,
I am in a fix trying to copy data to an array which is member of a
structure. What I am doing right now is:
char array = {0,1,2,3,4,5,6,7};
memcpy(structure.array, array, 8);
Is there a nicer way of doing this in a single statement?
|
by: n00dle |
last post by:
hi,
see if i want to copy the contents of a char arrary into a equally
size struct, assuming that the structure has no holes, padding etc., i
can use
structure = *(t_structure *) array;
but if i want to do things the other way round i.e. copy contents of
the structure to an char array. do i specifically need to have a loop
to do so, or...
|
by: Dennis Myrén |
last post by:
Hi.
I have an array of struct.
My question is, if i do:
STRUCT a = new STRUCT ;
STRUCT s = new STRUCT();
a = s;
since STRUCT is a value type, when assigning element 0 of the STRUCT array
as above,
|
by: Dan =o\) |
last post by:
Hey guys,
I'm getting really annoyed with this array... After selecting some items
from a list view, I take the selected text from the first column and store
it in an array, I then pass this data back to the parent of this window,
which then takes this list (of filenames) and downloads them to a scanner.
I step through the child's array...
| |
by: Tom Jastrzebski |
last post by:
Hello,
I was just testing VB.Net on Framework.Net 2.0 performance when I run into
the this problem.
This trivial code attached below executed hundreds, if not thousand times
faster in VB 6.0 than in .Net environment, under VS 2005 Beta 2. Does anyone
have any idea whether this will be addressed in the final release?
Thanks,
Tomasz
|
by: Sam Kong |
last post by:
Hello!
My question would not be very practical but just out of curiosity.
In JavaScript, Array is a subclass of Object.
Well maybe not exactly... but sort of...
For normal objects, you can access members by writing either of the
two.
obj.memberName
|
by: VK |
last post by:
(see the post by ASM in the original thread; can be seen at
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b>
as an option)
As that is not in relevance to "new Array() vs " question or to the
array performance, I dared to move it to a new thread.
Gecko takes undefined value strictly as per Book 4,...
|
by: eso40043 |
last post by:
Hi guys,
I've asked for help here once before with great results, I thought I'd try it again.
(I'm on Ubuntu 6.06 with python 2.4. Xemacs as editor.)
I have an image as a scipy array and I've made a mask array for it, sources (stars/galaxies/etc.) are flagged with 1, sky is 0. Now I want to blow up the size of each flagged source by a...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |