Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. how do i malloc in c# windowform?

how do i malloc in c# windowform?

Scheduled Pinned Locked Moved Windows Forms
csharpquestionvisual-studiodata-structuresperformance
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neodeaths
    wrote on last edited by
    #1

    hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice

    L L D J 4 Replies Last reply
    0
    • N neodeaths

      hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      neodeaths wrote:

      is there some other way to do it?

      A simple declaration might look like this;

      string[,] names = new string[5,4];

      More information and examples can be found on MSDN[^]. --edit If you don't know the size beforehand, there's two options;

      • Using an ArrayList[^]
      • A one-dimensional array can also be resized[^]

      I'd go for a generic list; it's dynamic and can be easily converted[^] to an array.

      I are Troll :suss:

      1 Reply Last reply
      0
      • N neodeaths

        hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        if you don't know the size, how on earth is malloc going to be any good? may I suggest you buy and study a beginners book on C# (or any language you choose), so you get the basics explained in a thorough and consistent way. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        1 Reply Last reply
        0
        • N neodeaths

          hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          The only reason to use malloc would be if you're passing stuff to unmanaged code. If all you want is an array, you just need to declare it. you don't have to worry about memory management the way you do with C.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          1 Reply Last reply
          0
          • N neodeaths

            hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice

            J Offline
            J Offline
            johannesnestler
            wrote on last edited by
            #5

            use a dynamic List<> or an ArrayList or any of the other nice things build into the .Net Framework (can be found under the System.Collections and System.Collections.Generic namespaces) And then start thinking in .Net! Buy a book, learn the basics. Don't get confused by the "C-style syntax" of C# - this IS NOT C in any way!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups