How do I create an int array of size 20 MB?
Do I have to use malloc or sbrk or something else?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
mallocis usually a good idea if you want something like 20MB. Most stacks are smaller and will crash the program if you try.or place it as a static/global variable:
or with
sbrkBut as the man page says “avoid using
sbrk“. The only time you should be usingsbrkis if you are implementing your own memory allocator.