What is memory segmentation?

10

I read about memory segmentation , however, I can not understand what memory segmentation really is and how it affects how my program works.

Illustration

See this sample program that generates a segmentation fault error:

int main(void)
{
    int* v = NULL;
    *v = 3;

    return 0;
}

Questions

  • What is memory targeting?
  • How memory segmentation influences the workings of my program?
  • The segmentation fault generated by the above program is related to memory segmentation or is it something else?
  • asked by anonymous 22.06.2017 / 18:36

    2 answers

    5

    Remember the page fault ? It's similar, but the reason is different. Page fault is inherent in the virtual memory system . The segmentation fault is a in the (probably) code.

    It occurs when you try to access a memory that is not available to your application. It was not allocated (reserved) for the running process. It also occurs when access is made to protected pages in the process, usually more when writing.

    Your error

    You can not write to address 0 in the memory of your application. And it's not just 0, others are also reserved. Actually not read in 0. You can not write in the code part (except special privilege), the code is fixed, it is static. The same goes for the static data part (usually placed by literals in your code).

    Remembering that the memory address in question is virtual, it has nothing to do with physical memory.

      

    What is Memory Segmentation?

    Memory areas where each part is:

    These are the segments, each with a different configuration in the operating system. These segments usually consist of several pages.

    When the imgr will leave an image here: link

    It can occur every time you perform an illegal, read, write, or execute operation. It's like in filesystem when trying to access a file without permission for that.

      

    How does Memory Segmentation influence how my program works?

    To develop the common nothing, but there has every organization of how the process will treat what is in memory. Of course he can not try to do operations on segments not allowed in the languages that allow this.

      

    Is the segmentation fault generated by the above program related to Memory Segmentation or is it something else?

    This error occurs because of access to something that is not authorized in that context. This does not occur in languages with managed memory, except for bug in runtime or language virtual machine.

    These bugs often occur because of a problem handling pointers, but there are other situations that may occur.

    Worse when segmentation fault does not occur. The hardware can not prevent all wrong access in memory and this becomes a logical error, much more difficult to detect.

        
    22.06.2017 / 18:58
    1

    Let's go in parts:  The problem with this code is that the variable V is initialized as NULL (pointing to nowhere), so the sequence is assigned the value 3 to it, which does not make sense since the pointer is not yet pointing to nowhere.

    Memory Segmentation is a technique widely used in operating systems to protect access to undue memory locations, an alternative method to memory paging. For that part of the memory is removed from the process with the use of registers and if a die wants to be access and is in this part removed a Segmentation Fault occurs. Memory Segmentation ensures better protection of your software from memory value edits via Hexing , for example.

    Font

        
    22.06.2017 / 18:56