Dynamic memory allocation

  • Thread starter Thread starter Le Minh
  • Start date Start date
L

Le Minh

Hi, i try to using unsafe programming to speed up my App.
i dont know how to dynamic memory allocate.

Anyone know it ?
Thanks,
Le Minh.
 
Le said:
Hi, i try to using unsafe programming to speed up my App.
i dont know how to dynamic memory allocate.

Anyone know it ?

Can you provide more details? What is it about your app that is slow and
how/why do you think using unsafe code will speed it up?
 
My App is processing image. It use GDI+ and it so slow. I want to manipulate
image in byte stream and hope it will better, so i need pointer.
 
Are you saying you dont know how to use pointers and addresses?

if so:

int var = 5; //assigns 5 to a memory space the size of int bytes

int * ptr;

ptr = &var; // makes ptr a reference poiting to the memory space of
var....sp ptr = 5;

*ptr = 10; //sets the memory space that ptr points to, to
10.........now var also equals 10.


*ptr= null; //frees memory and also means var is now null

....er does that help?
 
Are you saying you dont know how to use pointers and addresses?
No, i want a memory allocation function. It maybe like malloc function in
C++.
Can we do the same in C#?
Thanks
 
No, i want a memory allocation function. It maybe like malloc function in
C++.
Can we do the same in C#?

What's wrong with using the new operator to create a new byte array
(or other suitable array type)?

The only other allocation operator in C# is stackalloc to allocate
memory from the stack.

Then there are the Marshal.Alloc methods for allocating memory from a
native heap.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top