473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do you create an array of pointers to managed types? (C++/CLI)

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
cli:array<cli::interior_ptr<float>, 2>...

So, what do I do?

Oct 12 '07 #1
11 4600

<me**********@gmail.comwrote in message
news:11********************@z24g2000prh.googlegrou ps.com...
>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
cli:array<cli::interior_ptr<float>, 2>...

So, what do I do?
I think interior_ptr is a native type so you'd use a normal C++ array (not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).

Of course, you could store integer indices in the array instead of
interior_ptr.

Oct 12 '07 #2
On Oct 12, 4:52 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message

news:11********************@z24g2000prh.googlegrou ps.com...
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
cli:array<cli::interior_ptr<float>, 2>...
So, what do I do?

I think interior_ptr is a native type so you'd use a normal C++ array (not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).

Of course, you could store integer indices in the array instead of
interior_ptr.
I've tried using an array of tracking handles like this...

cli::array<float ^, 2^handles;
cli::array<float, 2^data;

data = gcnew cli::array<float, 2>{
{0, 0},
{10, 10},
{20, 20},
{30, 30},
{40, 40},
{50, 50},
{60, 40},
{70, 30},
{80, 20},
{90, 10},
{100, 0}
};

handles = gcnew cli::array<float ^, 2>{
{data[0, 0], data[0, 1]},
{data[1, 0], data[1, 1]}
};

data[0, 0] = float(100);
data[0, 1] = float(100);

MessageBox::Show(handles[0, 0]->ToString());

In this case the message box displays 0 instead of 100...

I've also tried replacing cli::array<float ^, 2^handles; with
cli::array<System::Object ^, 2^handles; with the same result...

Oct 16 '07 #3

<me**********@gmail.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...
On Oct 12, 4:52 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
><memeticvi...@gmail.comwrote in message

news:11********************@z24g2000prh.googlegro ups.com...
>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
cli:array<cli::interior_ptr<float>, 2>...
So, what do I do?

I think interior_ptr is a native type so you'd use a normal C++ array
(not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).

Of course, you could store integer indices in the array instead of
interior_ptr.

I've tried using an array of tracking handles like this...

cli::array<float ^, 2^handles;
cli::array<float, 2^data;

data = gcnew cli::array<float, 2>{
{0, 0},
{10, 10},
{20, 20},
{30, 30},
{40, 40},
{50, 50},
{60, 40},
{70, 30},
{80, 20},
{90, 10},
{100, 0}
};

handles = gcnew cli::array<float ^, 2>{
{data[0, 0], data[0, 1]},
{data[1, 0], data[1, 1]}
};

data[0, 0] = float(100);
data[0, 1] = float(100);

MessageBox::Show(handles[0, 0]->ToString());

In this case the message box displays 0 instead of 100...

I've also tried replacing cli::array<float ^, 2^handles; with
cli::array<System::Object ^, 2^handles; with the same result...
I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."

The key there is that T must be a reference type. System::Single isn't. As
a result, you get boxing, which means an independent copy.

Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it with
cli::array. So either: store indices instead of pointers, or use a native
array of interior_ptr.
Oct 16 '07 #4
On Oct 16, 12:24 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message

news:11**********************@z24g2000prh.googlegr oups.com...
On Oct 12, 4:52 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message
>news:11********************@z24g2000prh.googlegro ups.com...
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
cli:array<cli::interior_ptr<float>, 2>...
So, what do I do?
I think interior_ptr is a native type so you'd use a normal C++ array
(not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).
Of course, you could store integer indices in the array instead of
interior_ptr.
I've tried using an array of tracking handles like this...
cli::array<float ^, 2^handles;
cli::array<float, 2^data;
data = gcnew cli::array<float, 2>{
{0, 0},
{10, 10},
{20, 20},
{30, 30},
{40, 40},
{50, 50},
{60, 40},
{70, 30},
{80, 20},
{90, 10},
{100, 0}
};
handles = gcnew cli::array<float ^, 2>{
{data[0, 0], data[0, 1]},
{data[1, 0], data[1, 1]}
};
data[0, 0] = float(100);
data[0, 1] = float(100);
MessageBox::Show(handles[0, 0]->ToString());
In this case the message box displays 0 instead of 100...
I've also tried replacing cli::array<float ^, 2^handles; with
cli::array<System::Object ^, 2^handles; with the same result...

I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."

The key there is that T must be a reference type. System::Single isn't. As
a result, you get boxing, which means an independent copy.

Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it with
cli::array. So either: store indices instead of pointers, or use a native
array of interior_ptr.
"boxing" is the key word. I've been trying to get a grasp on what was
happening here for a couple days now. You're a life saver.

Given my actual problem, compiling a list of references to individual
values in a data set, the "store indices" option is out. It would be
to complex. So, I'm trying to figure how to store a list of type
interior_ptr. I'm having some difficulty getting it to work though.

Could you provide me with an example?

Oct 16 '07 #5
On Oct 16, 12:24 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message

news:11**********************@z24g2000prh.googlegr oups.com...
On Oct 12, 4:52 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message
>news:11********************@z24g2000prh.googlegro ups.com...
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
cli:array<cli::interior_ptr<float>, 2>...
So, what do I do?
I think interior_ptr is a native type so you'd use a normal C++ array
(not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).
Of course, you could store integer indices in the array instead of
interior_ptr.
I've tried using an array of tracking handles like this...
cli::array<float ^, 2^handles;
cli::array<float, 2^data;
data = gcnew cli::array<float, 2>{
{0, 0},
{10, 10},
{20, 20},
{30, 30},
{40, 40},
{50, 50},
{60, 40},
{70, 30},
{80, 20},
{90, 10},
{100, 0}
};
handles = gcnew cli::array<float ^, 2>{
{data[0, 0], data[0, 1]},
{data[1, 0], data[1, 1]}
};
data[0, 0] = float(100);
data[0, 1] = float(100);
MessageBox::Show(handles[0, 0]->ToString());
In this case the message box displays 0 instead of 100...
I've also tried replacing cli::array<float ^, 2^handles; with
cli::array<System::Object ^, 2^handles; with the same result...

I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."

The key there is that T must be a reference type. System::Single isn't. As
a result, you get boxing, which means an independent copy.

Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it with
cli::array. So either: store indices instead of pointers, or use a native
array of interior_ptr.
System::Collections::ArrayList ^pointers = gcnew
System::Collections::ArrayList;

pointers->Add(&data[0,0]);

/*
error C2664: 'System::Collections::ArrayList::Add' : cannot convert
parameter 1 from 'cli::interior_ptr<Type>' to 'System::Object ^'
*/

Oct 16 '07 #6
>I said "You can make .NET arrays of tracking handles of course
>(cli::array<T^, 2where T is a .NET reference type)."

The key there is that T must be a reference type. System::Single isn't.
As
a result, you get boxing, which means an independent copy.

Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it with
cli::array. So either: store indices instead of pointers, or use a
native
array of interior_ptr.

System::Collections::ArrayList ^pointers = gcnew
System::Collections::ArrayList;

pointers->Add(&data[0,0]);

/*
error C2664: 'System::Collections::ArrayList::Add' : cannot convert
parameter 1 from 'cli::interior_ptr<Type>' to 'System::Object ^'
*/
A native array of interior_ptr, like perhaps:

std::vector<cli::interior_ptr<float>pointers;
pointers.push_back(&data[0,0]);
Oct 16 '07 #7
On Oct 16, 5:54 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."
The key there is that T must be a reference type. System::Single isn't.
As
a result, you get boxing, which means an independent copy.
Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it with
cli::array. So either: store indices instead of pointers, or use a
native
array of interior_ptr.
System::Collections::ArrayList ^pointers = gcnew
System::Collections::ArrayList;
pointers->Add(&data[0,0]);
/*
error C2664: 'System::Collections::ArrayList::Add' : cannot convert
parameter 1 from 'cli::interior_ptr<Type>' to 'System::Object ^'
*/

A native array of interior_ptr, like perhaps:

std::vector<cli::interior_ptr<float>pointers;
pointers.push_back(&data[0,0]);
A native array can not contain a managed type (cli::interior_ptr)

Oct 17 '07 #8

<me**********@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
On Oct 16, 5:54 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."
>The key there is that T must be a reference type. System::Single
isn't.
As
a result, you get boxing, which means an independent copy.
>Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it
with
cli::array. So either: store indices instead of pointers, or use a
native
array of interior_ptr.
System::Collections::ArrayList ^pointers = gcnew
System::Collections::ArrayList;
pointers->Add(&data[0,0]);
/*
error C2664: 'System::Collections::ArrayList::Add' : cannot convert
parameter 1 from 'cli::interior_ptr<Type>' to 'System::Object ^'
*/

A native array of interior_ptr, like perhaps:

std::vector<cli::interior_ptr<float>pointers;
pointers.push_back(&data[0,0]);

A native array can not contain a managed type (cli::interior_ptr)
Ahh... the interior_ptr declaration clearly states that this isn't possible.
interior_ptr can only be used as a local variable.

Looks like storing indices is your only option.
Oct 17 '07 #9
On Oct 17, 12:44 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message

news:11**********************@i13g2000prf.googlegr oups.com...
On Oct 16, 5:54 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."
The key there is that T must be a reference type. System::Single
isn't.
As
a result, you get boxing, which means an independent copy.
Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it
with
cli::array. So either: store indices instead of pointers, or use a
native
array of interior_ptr.
System::Collections::ArrayList ^pointers = gcnew
System::Collections::ArrayList;
pointers->Add(&data[0,0]);
/*
error C2664: 'System::Collections::ArrayList::Add' : cannot convert
parameter 1 from 'cli::interior_ptr<Type>' to 'System::Object ^'
*/
A native array of interior_ptr, like perhaps:
std::vector<cli::interior_ptr<float>pointers;
pointers.push_back(&data[0,0]);
A native array can not contain a managed type (cli::interior_ptr)

Ahh... the interior_ptr declaration clearly states that this isn't possible.
interior_ptr can only be used as a local variable.

Looks like storing indices is your only option.
The amount of complexity this would introduce into my project is
unreasonable. First of all I'd have to store references to a DataSet
the name of the DataTable, the name of the DataColumn and the index of
the DataRow. And, then what if something changes? Well then I have to
reprocess and redraw everything? The data my program is used to
process is usually incredibly vast and complicated. Consisting of
hundreds of thousands DataRows.

Is garbage collection worth bring a system to it's knees every time
some one changes a digit in a DataGridView or something? This is
stupid!

There has to be a way to create an array of references to the memory
locations of the individual values in the DataSet. I won't accept that
there isn't a better way to do this. I could do it in with 3 lines of
code in standard C++!

Oct 22 '07 #10

<me**********@gmail.comwrote in message
news:11**********************@q5g2000prf.googlegro ups.com...
On Oct 17, 12:44 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
><memeticvi...@gmail.comwrote in message

news:11**********************@i13g2000prf.googleg roups.com...
On Oct 16, 5:54 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."
>The key there is that T must be a reference type. System::Single
isn't.
As
a result, you get boxing, which means an independent copy.
>Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it
with
cli::array. So either: store indices instead of pointers, or use a
native
array of interior_ptr.
System::Collections::ArrayList ^pointers = gcnew
System::Collections::ArrayList;
pointers->Add(&data[0,0]);
/*
error C2664: 'System::Collections::ArrayList::Add' : cannot convert
parameter 1 from 'cli::interior_ptr<Type>' to 'System::Object ^'
*/
>A native array of interior_ptr, like perhaps:
>std::vector<cli::interior_ptr<float>pointers;
pointers.push_back(&data[0,0]);
A native array can not contain a managed type (cli::interior_ptr)

Ahh... the interior_ptr declaration clearly states that this isn't
possible.
interior_ptr can only be used as a local variable.

Looks like storing indices is your only option.

The amount of complexity this would introduce into my project is
unreasonable. First of all I'd have to store references to a DataSet
the name of the DataTable, the name of the DataColumn and the index of
the DataRow. And, then what if something changes? Well then I have to
Why? If you have an array<float,2>, why not store a handle to the array,
and the row and column indices?
reprocess and redraw everything? The data my program is used to
process is usually incredibly vast and complicated. Consisting of
hundreds of thousands DataRows.

Is garbage collection worth bring a system to it's knees every time
some one changes a digit in a DataGridView or something? This is
stupid!

There has to be a way to create an array of references to the memory
locations of the individual values in the DataSet. I won't accept that
there isn't a better way to do this. I could do it in with 3 lines of
code in standard C++!

Oct 22 '07 #11
On Oct 22, 5:55 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message

news:11**********************@q5g2000prf.googlegro ups.com...
On Oct 17, 12:44 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<memeticvi...@gmail.comwrote in message
>news:11**********************@i13g2000prf.googleg roups.com...
On Oct 16, 5:54 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."
The key there is that T must be a reference type. System::Single
isn't.
As
a result, you get boxing, which means an independent copy.
Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can't use it
with
cli::array. So either: store indices instead of pointers, or use a
native
array of interior_ptr.
System::Collections::ArrayList ^pointers = gcnew
System::Collections::ArrayList;
pointers->Add(&data[0,0]);
/*
error C2664: 'System::Collections::ArrayList::Add' : cannot convert
parameter 1 from 'cli::interior_ptr<Type>' to 'System::Object ^'
*/
A native array of interior_ptr, like perhaps:
std::vector<cli::interior_ptr<float>pointers;
pointers.push_back(&data[0,0]);
A native array can not contain a managed type (cli::interior_ptr)
Ahh... the interior_ptr declaration clearly states that this isn't
possible.
interior_ptr can only be used as a local variable.
Looks like storing indices is your only option.
The amount of complexity this would introduce into my project is
unreasonable. First of all I'd have to store references to a DataSet
the name of the DataTable, the name of the DataColumn and the index of
the DataRow. And, then what if something changes? Well then I have to

Why? If you have an array<float,2>, why not store a handle to the array,
and the row and column indices?
reprocess and redraw everything? The data my program is used to
process is usually incredibly vast and complicated. Consisting of
hundreds of thousands DataRows.
Is garbage collection worth bring a system to it's knees every time
some one changes a digit in a DataGridView or something? This is
stupid!
There has to be a way to create an array of references to the memory
locations of the individual values in the DataSet. I won't accept that
there isn't a better way to do this. I could do it in with 3 lines of
code in standard C++!
Because, the indices change whenever something is inserted or
removed... And, then I'd have to reprocess the data.

Oct 23 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Alper AKCAYOZ | last post by:
Hello Esteemed Developers and Experts, I have been using Microsoft Visual C++ .NET for 1 year. During this time, I have searhed some topics over internets. Most of the topics about .NET is...
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...
1
by: Ioannis Vranos | last post by:
This compiles: value class SomeClass {}; int main() {
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 ...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
13
by: bonk | last post by:
Hello, I am trying to create a dll that internally uses managed types but exposes a plain unmanaged interface. All the managed stuff shall be "wrapped out of sight". So that I would be able to...
1
by: Russell Mangel | last post by:
Sorry about the Cross-Post, I posted my question in the wrong group. Hello, What is the simplest way to create a dynamic collection (during run-time), using basic C (Struct data types). Since...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.