why use new() function in C++?
-
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
-
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
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!
-
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!
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
-
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
kitty5 wrote:
do I access buff the same as an array?
yes
Let's execute on the customer-facing market-driven swim-lane paradigm!