Skip to main content

Posts

Showing posts from February, 2017

C++ Memory for Beginners

This is a a short introduction to the C++ memory model. In C++ the programmer has big control over how the program handles it memory, but you usually do not have to think a lot about it. Still it is good to know the basics to understand how things work under the hood. The memory a program uses is typically divided into different areas, called this is simple model of segments: The code segment , where the compiled program is stored in memory. The data segment where global and static variables are stored. The heap , where dynamically allocated variables are allocated from. The stack , where function parameters, local variables, and other function-related information are stored. The heap The heap segment (also known as the “free store”) keeps track of memory used for dynamic memory allocation. The heap is not automatically handled. You allocate memory and delete allocations yourself. In C++ you use the new operator to allocate memory in heap segment. You free the memory...