473,467 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cli::array and c++ dynamic array

5 New Member
I am new to CLI/c++ and have some question on the 2 type of array stated above. I am doing some numerical calculation on large number of sample and face some problem with the speed on accessing the data in array.

As example, accessing data from
Expand|Select|Wrap|Line Numbers
  1. array<int>^ data = gcnew array<int>(1000000);
  2. for(int i = 0; i < data->GetLength(0); i++){
    data[i] = i;
    }
  3.  
is far slower compare to

Expand|Select|Wrap|Line Numbers
  1. int *data;
  2. data = new int[1000000];
  3. for(int j = 0; j <1000000; j++){
    data[j] = j;
    }
  4.  
I wrote finish a code using dynamic array and it run faster compare to the one using CLI::array.

Anyone know why this happen? Is it the way i write my code wrong? Currently working in console enviroment but will move to GUI so i plan to change all the the array to CLI::array. Would C# be better if i plan to construct the program?
Mar 18 '09 #1
4 9328
weaknessforcats
9,208 Recognized Expert Moderator Expert
You did just fine. The slowdown comes with gcnew. This is a garbage-collected array and the garbage collector needs time. The C++ new operator has none of that. Instead, you have the resonsibility to clean up after yourself.

Managed code is great when time is not an issue.

As a side note have you considered creating private process heap and allocating from that? You can use HeapCreate and then when you are done you just delete the heap and there go your leaks.
Mar 18 '09 #2
rahxephon
5 New Member
Thanks for the reply. I am new to programming in windows, so I am trying out few things for the program. Will try to use HeapCreate to see how it goes.
Mar 19 '09 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Get a copy of Windows viaC/C++ by Jeffrey Richter 2007. Pay attention to page 528.
Mar 19 '09 #4
rahxephon
5 New Member
Just found the book in my local library. Will look through it and see how it goes.
Mar 20 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I...
3
by: GrkEngineer | last post by:
I recently had to use someone's struct from a native app to receive data over Udp. The struct has a array member which looked like this: struct sensorHdr{ char sName; }; When I tried to make...
2
by: None | last post by:
Hello To get an understanding of UI threads in C++/CLI, I attempted to duplicate the following C# example: ...
0
by: None | last post by:
Hello Suppose a C++/CLI application would need a large array (30-50) of an ActiveX Component. Since creating ActiveX components at runtime in C++/CLI is very difficult at best, the only other...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
4
by: Michel Esber | last post by:
Hello, Environment: db2 V8 FP 13 LUW Our application currently uses: insert into table values ('A'),('B'),...('Z') We have used CLI arrays inserts (1000 array and commit size) and...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
11
by: memeticvirus | last post by:
I have an array cli::array<float, 2and I would like to access a subset of it's values by compiling an array of pointers. But, it's not possible to create an array of type...
1
by: 8rea | last post by:
Hello, I want to make a matrix like this: System::Drawing::Drawing2D::Matrix^ L; L=gcnew( System::Drawing::Drawing2D::Matrix::Matrix(rect,plgpts)); System::Drawing::Drawing2D::Matrix^ L;...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
1
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.