Dynamic memory allocation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Le Minh

    Dynamic memory allocation

    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.


  • Tom Porterfield

    #2
    Re: Dynamic memory allocation

    Le Minh wrote:
    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?
    --
    Tom Porterfield

    Comment

    • Le Minh

      #3
      Re: Dynamic memory allocation

      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.


      Comment

      • Daniel

        #4
        Re: Dynamic memory allocation

        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?


        "Le Minh" <hanami279@hotm ail.comwrote in message
        news:%23yrl%23M K6GHA.4644@TK2M SFTNGP05.phx.gb l...
        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.
        >

        Comment

        • Le Minh

          #5
          Re: Dynamic memory allocation

          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


          Comment

          • Mattias Sjögren

            #6
            Re: Dynamic memory allocation

            >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

            --
            Mattias Sjögren [C# MVP] mattias @ mvps.org
            http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
            Please reply only to the newsgroup.

            Comment

            Working...