Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dynamic memory allocation

1 view
Skip to first unread message

Jakop Nielsen

unread,
Jun 20, 2003, 2:15:17 PM6/20/03
to
I wanted to play arround with unsafe code in c# but failed to make a simple
allocation.

How do I do something like this c code in c#?

int *p=new int[100];


Nicholas Paldino [.NET/C# MVP]

unread,
Jun 20, 2003, 2:17:22 PM6/20/03
to
Jakop,

Simple, declare an integer array, like this:

// Declare an integer array.
int[] p = new int[100];

This will create an integer array with 100 elements in it.

Hopet his helps.


--
- Nicholas Paldino [.NET/C# MVP]
- nicholas...@exisconsulting.com


"Jakop Nielsen" <j...@home.mail.dk> wrote in message
news:bcvivk$1k5k$1...@news.cybercity.dk...

Troy Reagan

unread,
Jun 20, 2003, 2:47:42 PM6/20/03
to
Hi Jakop,
In the MSDN it has a sample tutorial about unsafe code see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/
vcwlkunsafecodetutorial.asp and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/
vclrfUnsafe.asp (be careful of word wrap). Basically, you must use the
unsafe keyword and compile with the /unsafe command-line parameter. You may
also need to use the fixed statement to keep the garbage collector from
moving the memory on you.
Troy

"Jakop Nielsen" <j...@home.mail.dk> wrote in message
news:bcvivk$1k5k$1...@news.cybercity.dk...

Marcus Cuda

unread,
Jun 20, 2003, 4:00:57 PM6/20/03
to
try:
unsafe {
int* p = stackalloc int[100];
}

see section 25.7 Stack allocation and 25.8 Dynamic memory allocation
of the C# Spec.
Marcus

0 new messages