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
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in ARRAYS
- Two different numbers in an array which their sum equals to a given value
- how to fill out the table with next values in array with one button
- How to sort a multi-dimensional array by the second array in descending order?
- Looping over defined array elements in Fortran
- Array appending after each onclick and loop in javascript
- PHP : How can I check Array in array?
- store numpy array in mysql
- Java Assign a Value to an array cell
- Saving FileSystemInfo Array to File
- Notice: Undefined offset: 1, but there is such offset
- How can I determine the index of the same set of characters between two strings that are of different lengths?
- Caused by: java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
- Pull out first occurrences from array
- How to read a file then store to array and then print?
- C++ won't read in scientific notation data from a .txt file
Related Questions in LIMITS
- Custom glibc in non-standard path on machine with uclibc and gcc compiled against uclibc
- Java PostgreSQL error on large query: An I/O error occurred while sending to the backend
- what if i give duplicate entries in limits.conf for same parameter with a different value?
- Apache can't create more than 400 workers
- Documentation for specific entity attribute's data size limits of Microsoft Dynamics CRM 2016
- How to limit user of only insert number into textfield?
- Matlab variable count limit
- Colorize Scatterplot with upper and lower limits
- Repeat Foreach limit
- "max_questions" limit not respected when running MySQL query via PHP
- Twitter API rate limits for posting updates
- Do public Twitter RSS feeds have access limits?
- Limit a MySQL query to only one 1 result from each set
- Checking if an input is within its range of limits in C++
- Array of size LONG_MAX
Related Questions in VARIABLE-DECLARATION
- Declaring and Initialising variables
- How many times are primitive data types allocated inside loops?
- Trouble assigning/declaring a __64int (long long int) array
- Can I dim multiple objects as Integer / Variant / etc. in one line?
- C++: Variables with same name (order of operations) (Scope)
- Why can't I give array elements a value outside of a method in Android Studio?
- Must declare the scalar variable @ when updating table
- Which one gives me better performance in variables declaration?
- Variable is not declared even it is
- How can you use a method from a parent controller to set a private variable in php?
- Storing default type value in class member declarations
- Multiple-Target Assignments
- PHP - declaring each variable before insert / update or placing each variable in the insert / update in quotes?
- Set a class static
- Object destructuring for structuring a new object
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.