I need to save a “large” file (say, a little less than 2 MB) in memory, and I want to know if it’s correct to use
char buffer[2048000];
Is there a better way to handle this? Any performance issues when using large char arrays?
Yes, there may be problems, most C implementations will allocate this buffer on the stack, if it is an automatic storage time variable, and the amount of "stack memory" available for use can be surprisingly small.
Best used mallocfor anything more than a few kilobytes. Remember to call freeat the appropriate point.
malloc
free
static - .
static
, . , .
, . . , malloc mmap .
mmap
:
1) . , . , , .
2) ( malloc). .
3) . , . .
, 2048000 . , 2048000 , . , , , , .
- malloc . , NULL ( ). , , , .
, ( , ), char. , . , .
, 2 , 10 200 , , .
, , ( ), : . , , , , , , , , , , , .
Source: https://habr.com/ru/post/1629552/More articles:How to convert latin character to HTML Entity (decimal) in C #? - c #Replace the string with the equivalent HTML. Besides tags - javascriptSwift custom action controller - iosHTML5 User Controls Not Displaying Full Screen in Mozilla Firefox - javascriptA number divided by a string is not numeric - pythonHow to get Facebook posts for og_object or common URL? - facebook-graph-apiNo mapping found for HTTP request with xxx URI in DispatcherServlet named xx - javaPassing null values to overloaded methods in javaAn error occurred while saving and reloading the guava bloom filter - need help finding an error in the code - javaElastic Search Wizard Not Found Exception - elasticsearchAll Articles