I need to declare an array of size LONG_MAX (2147483647, in the c library <limits.h>), and I really need this for solving a problem. But the code gives me and error: if I write long int v[LONG_MAX]; the compiler gives size of array 'v' is too large.
How can I solve this problem?
Array of size LONG_MAX
290 views Asked by giacomotb At
2
There are 2 answers
0
lulyon
On
If you have to use so large memory, which is do not allowed to allocate by system, you can use memory mapping instead.
fd=open(name, flag, mode);
if(fd<0)
...
ptr=mmap(NULL, len , PROT_READ|PROT_WRITE, MAP_SHARED , fd , 0);
// use the virtual memory that ptr pointed to, like what you do with arrays.
...
munmap( p_map, len);
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in ARRAYS
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- What does: "char *argv[]" mean?
- How to populate two dimensional array
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- Function is returning undefined but should be returning a matched object from array in JavaScript
- The rules of Conway's Game of Life aren't working in my Javascript version. What am I doing wrong?
- Array related question, cant find the pattern
- Setting the counter (j) for (inner for loop)
- I want to flip an image (with three channels RGB) horizontally just using array slicing. How can I do it with python?
- Numpy array methods are faster than numpy functions?
- How to enter data in mongodb array at specific position such that if there is only 2 data in array and I want to insert at 5, then rest data is null
- How to return array to ArrayPool when it was rented by inner function?
- best way to remove a word from an array in a react app
- Vue display output of two dimensional array
- Undot Array with Wildcards in Laravel
Related Questions in LIMITS
- Does Jekyll suffer anywhere from the 50-item for-loop maximum declared by Shopify's Liquid specification?
- limit scroll boundaries in webview
- Are there any constants in C++ which can be used as minimum/maximum values in comparisons
- Why pairplot gives asymmetrical (different upper- and lower-triangle) plots when it should not?
- R ggplot limiting dates on plot x-axis
- Why std::floor(1 - std::numeric_limits<float>::min()) evaluates to 1
- Setting High and Low Limit for Inventory
- What is the maximal array size in C?
- How can I mitigate integer overflow in this code?
- fcm Quotas and Limits per device and message
- Set limits in histogram for xaxis including 0 values
- Google Analytics Management API - batch request return "Quota Error: Rate limit for writes exceeded"
- Is there a maximum number of INCLUDES in a Classic ASP page?
- MySQL REPLACE : How replace all occurrences of a char in every distinct substring delimited by the same head and tail
- C error: size of array is too large
Related Questions in VARIABLE-DECLARATION
- Why would anyone declare a variable before defining it? Please provide example
- Writing a compiler frontend. When should I check if a variable was declared or not?
- how to declare an array with explicit type in vlang?
- Inline variables aren't working in TMS Web Core
- C - Struct variable inside callee function, should it be a pointer or dosent it matter
- Can I declare an array of integers in JSON without listing each element explicitly?
- my variable resetting after one loop in a for loop, not sure why
- Can't pass lat, lng to weatherbit API, ReferenceError: data is not defined
- Why Does PowerShell Complain It Can't Retrieve a Variable?
- Is it possible to declare a type with a set bit width in c++ without using a struct?
- Error in setting up my Fyne container, not initialized or declared properly
- Why isn't variable 'result' always declared?
- String concatenation with string literal and non string literal
- Declaring and Writing a For Loop in Pseudocode
- in C, why do variables need to be declared before use but functions dont?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
On pretty much every system that exists, variables that are declared as local arrays with a fixed size are placed on the stack.
The C standard (5.2.4.1) only guarantees that programs running on an OS should be able to hold an object of size 65535 bytes. And no matter what the standard says, the OS will set a stack limit for your process.
If you declare a object that is too large, as far as the C standard is concerned, you get the compiler error you describe. Otherwise, if you pass that check but still use up too much stack, with nested function calls etc, you get a runtime error: stack overflow.
The preferred way to solve this is to always allocate large objects using dynamic memory allocation. Then the objects are allocated on the heap, and the RAM of your the computer pretty much sets the limit.