Click here to Skip to main content
15,917,061 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: srand in c or c++ doesn't really Generate Random Numbers ? Pin
snailflying3-Jul-07 15:53
snailflying3-Jul-07 15:53 
QuestionInterior Pointer vs Handle Pin
iddqd5152-Jul-07 4:37
iddqd5152-Jul-07 4:37 
AnswerRe: Interior Pointer vs Handle Pin
led mike2-Jul-07 5:07
led mike2-Jul-07 5:07 
GeneralRe: Interior Pointer vs Handle Pin
iddqd5152-Jul-07 5:25
iddqd5152-Jul-07 5:25 
GeneralRe: Interior Pointer vs Handle Pin
George L. Jackson2-Jul-07 14:23
George L. Jackson2-Jul-07 14:23 
GeneralRe: Interior Pointer vs Handle Pin
iddqd5153-Jul-07 3:30
iddqd5153-Jul-07 3:30 
GeneralRe: Interior Pointer vs Handle Pin
Geo Pa3-Jul-07 8:02
Geo Pa3-Jul-07 8:02 
GeneralRe: Interior Pointer vs Handle Pin
iddqd5153-Jul-07 8:35
iddqd5153-Jul-07 8:35 
Ok, thanks, that's a good example of where interior pointers can simplify things. But you could do similarly with just handles if you have an array of 'handle to typeX' even if its not quite as nice a solution.

(Sorry I'm not sure how to use the code tag and ignore HTML so the array type is shown.)

#include "stdafx.h"
using namespace System;

// Can multiply the array elements when the array type is handle to type
// rather than needing interior pointers.
// A little silly with int due to boxing costs but imagine with an array of
// ref class objects where you do perform some useful change to each element
void MulArray( array<int^>^ data, int value )
{
for each(int^% i in data)
{
*i *= value;
}
}

// Tracking references point to the whole managed object.
// Using a tracking reference here does not make much sense since using a
// tracking handle has the same affect in this case.
void PrintArray( array<int^>^ vals )
{
for each (int val in vals)
{
Console::WriteLine(val);
}
}

int main(array<System::String ^> ^args)
{
// Tracking handles refer to the whole managed object.
// They can be initialized with gcnew.
array<int^>^ values = { 1, 2, 3, 4, 5 };

MulArray(values, 2);
PrintArray(values);

return 0;
}

Now I understand why you'd want your version in some cases where you're being passed an array<int>^ that you didn't choose to create. In theory you could create a new array (of array<int^>^) to copy the array<int>^ to use with my version if you wanted to avoid interior pointers and make the code verifiable. I'm just trying to draw a solid line in my mind dividing the uses of handles and interior pointers. Like I said (and you just showed), they can be useful for pointer semantics. But you can still find a way to avoid them and use handles to point to interior members. So are the only time they're absolutely necessary are when you must have pointer semantics and in some interop scenarios (where native pointers can convert implicitly to interior pointers but not handles)? They can simplify some situations where you're pointing to interior members of a ref class but you can still get around doing so via handles (even if it may not be as elegant and performant as the interior pointer solution).
QuestionDataSet Array Pin
MAW301-Jul-07 22:36
MAW301-Jul-07 22:36 
AnswerRe: DataSet Array Pin
George L. Jackson2-Jul-07 14:32
George L. Jackson2-Jul-07 14:32 
GeneralRe: DataSet Array Pin
MAW302-Jul-07 17:23
MAW302-Jul-07 17:23 
GeneralRe: DataSet Array Pin
George L. Jackson2-Jul-07 23:57
George L. Jackson2-Jul-07 23:57 
GeneralRe: DataSet Array Pin
MAW303-Jul-07 11:46
MAW303-Jul-07 11:46 
GeneralRe: DataSet Array Pin
George L. Jackson5-Jul-07 8:18
George L. Jackson5-Jul-07 8:18 
GeneralRe: DataSet Array Pin
MAW305-Jul-07 11:44
MAW305-Jul-07 11:44 
QuestionHow to get the seconds/milliseconds in DateTime? Pin
C#Coudou1-Jul-07 16:26
C#Coudou1-Jul-07 16:26 
AnswerRe: How to get the seconds/milliseconds in DateTime? Pin
Luc Pattyn2-Jul-07 5:28
sitebuilderLuc Pattyn2-Jul-07 5:28 
GeneralRe: How to get the seconds/milliseconds in DateTime? Pin
led mike2-Jul-07 5:39
led mike2-Jul-07 5:39 
GeneralRe: How to get the seconds/milliseconds in DateTime? Pin
Luc Pattyn2-Jul-07 6:05
sitebuilderLuc Pattyn2-Jul-07 6:05 
GeneralRe: How to get the seconds/milliseconds in DateTime? Pin
C#Coudou2-Jul-07 19:50
C#Coudou2-Jul-07 19:50 
Questionnetwork speed detection Pin
C#Coudou1-Jul-07 15:40
C#Coudou1-Jul-07 15:40 
AnswerRe: network speed detection Pin
Perspx2-Jul-07 11:24
Perspx2-Jul-07 11:24 
Questionhow to retrieve sub directorires under a specified directory Pin
cy163@hotmail.com29-Jun-07 23:24
cy163@hotmail.com29-Jun-07 23:24 
AnswerRe: how to retrieve sub directorires under a specified directory Pin
Luc Pattyn29-Jun-07 23:40
sitebuilderLuc Pattyn29-Jun-07 23:40 
QuestionString Format how it works. Pin
earlgraham29-Jun-07 6:04
earlgraham29-Jun-07 6:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.