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. C / C++ / MFC
  4. why use new() function in C++?

why use new() function in C++?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structures
4 Posts 2 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.
  • K Offline
    K Offline
    kitty5
    wrote on last edited by
    #1

    my question is when would you want to use new()? do you only use it if you don't quite know how large to make your array? I need to create a buffer and allocate enough space to be able to hold my data that I'll be getting from an external source. However, I know exactly how large it needs to be. (i.e. int x[1000][1000]; int y[1000][1000]; ) I wouldn't need to use new(), correct?:confused: Also, i know that my computer an unsigned int is 4bytes and an unsigned long is 4bytes. why would one use int over long and vise versa?:confused: To confirm: if I do: ULONG x[1000][1000]; I've created a double array of 1000 x 1000 and each element of that array can hold data the size of 4 bytes? Thanks,:-D

    Kitty5

    C 1 Reply Last reply
    0
    • K kitty5

      my question is when would you want to use new()? do you only use it if you don't quite know how large to make your array? I need to create a buffer and allocate enough space to be able to hold my data that I'll be getting from an external source. However, I know exactly how large it needs to be. (i.e. int x[1000][1000]; int y[1000][1000]; ) I wouldn't need to use new(), correct?:confused: Also, i know that my computer an unsigned int is 4bytes and an unsigned long is 4bytes. why would one use int over long and vise versa?:confused: To confirm: if I do: ULONG x[1000][1000]; I've created a double array of 1000 x 1000 and each element of that array can hold data the size of 4 bytes? Thanks,:-D

      Kitty5

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      kitty5 wrote:

      I wouldn't need to use new(), correct?

      you would most certainly use new[] with an array that large. it's bad practice to put such a large array on the stack.

      Let's execute on the customer-facing market-driven swim-lane paradigm!

      K 1 Reply Last reply
      0
      • C Chris Losinger

        kitty5 wrote:

        I wouldn't need to use new(), correct?

        you would most certainly use new[] with an array that large. it's bad practice to put such a large array on the stack.

        Let's execute on the customer-facing market-driven swim-lane paradigm!

        K Offline
        K Offline
        kitty5
        wrote on last edited by
        #3

        Chris Losinger wrote:

        you would most certainly use new[] with an array that large. it's bad practice to put such a large array on the stack.

        if it's a double array would you do: ULONG *buff; buff = new ULONG [1000][1000]; do I access buff the same as an array? i.e. buff[0][10] = 0x12345678; Thanks!

        Kitty5

        C 1 Reply Last reply
        0
        • K kitty5

          Chris Losinger wrote:

          you would most certainly use new[] with an array that large. it's bad practice to put such a large array on the stack.

          if it's a double array would you do: ULONG *buff; buff = new ULONG [1000][1000]; do I access buff the same as an array? i.e. buff[0][10] = 0x12345678; Thanks!

          Kitty5

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          kitty5 wrote:

          do I access buff the same as an array?

          yes

          Let's execute on the customer-facing market-driven swim-lane paradigm!

          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