Computer Memory

بواسطة: Brilliant

Overview

This course was created in collaboration with Kenji Ejima and Kristian Takvam, senior members of Brilliant's software engineering team.

How is the memory managed in the running program? How does the OS manage it when multiple programs are running? What are the memory related features that the CPU provides?
This course will guide you through understanding memory management, layer by layer, so that you can answer the questions above and write efficient programs.

Syllabus

  • Introduction to Memory: What memory is, and how to represent it.
    • Retrieving Data from a Computer: Computers work by storing data both quickly and slowly, both persistently and temporarily.
    • Binary, Decimal, and Hexadecimal: These three numeric bases from discrete math are key for understanding how computers really work.
    • Linear Memory Model: Discover how every computer program really sees the computer's memory when you get under the hood.
    • Memory Layout: The linear memory model allows large pieces of data to be stored in byte-sized fragments.
  • Memory of Programs: Segments of memory.
    • Compiling Source Files to Executables: The programs you run are made up of bytes in memory, just like everything else.
    • Memory Segments: A running program uses four different parts of the computer's memory for different purposes.
    • The Code and Static Segments: Some parts of memory hold information that the program shouldn't be allowed to change.
    • The Stack Segment: The stack allows multiple functions to work together.
    • The Heap Segment: The heap is where memory for data structures can be easily allocated and freely shared.
  • Virtual Memory: How the OS manages memory.
    • Processes: A computer can hold many programs, each of which think they're using the same memory. How can this be?
    • Virtual and Physical Memory: Memory, as seen by every running computer program on your computer, is an elaborate virtual reality.
    • Memory Pages: The computer's actual memory is managed in large chunks, called "pages."
    • MMU and the OS: Your computer's processor and operating system work together to give each programs its own memory.
  • Techniques for Performance: OS features for efficient memory management.
    • Page Cache: The page cache keeps information from the hard drive in RAM for faster access.
    • Memory Mapping: A technique that helps the operating system access only small parts of big files.
    • Demand Load: Even after you think you've opened a file, the operating system may be lying to you.
    • Page Sharing and Copy-on-Write: Change is hard, and operating systems speed your computer up by assuming you'll avoid changes.
  • Shared Libraries: Linking and loading shared libraries to effectively reuse code.
    • Libraries: Programs do not exist in isolation. When they run, they need to be connected to libraries.
    • Relocation: After the compiler is done with your program, there is still missing information.
    • Position Independent Code: An advanced technique can avoid the need for relocations.
    • Procedure Linkage Table: See how the linkage information can be stored indirectly, without slowing programs down.
  • Caching: A fundamental technique to improve performance.
    • Caching Overview: Caching is a fundamental technique for speeding up computer systems.
    • Details of Caching: Computer processors use a few different techniques for deciding what to cache.
    • Practical Uses of Caching: The same caching techniques apply to your computer and to the global internet.
    • DRAM, SRAM, and CPU Caches: Caching always needs to consider tradeoffs between cost and performance.
    • Computer Memory Architecture: All modern processors use a similar pattern of caches.
Computer Memory
الذهاب الي الدورة

Computer Memory

بواسطة: Brilliant

  • Brilliant
  • مدفوعة
  • الإنجليزية
  • متاح شهادة
  • متاح في أي وقت
  • beginner
  • N/A
8.1.2PHP Version974msRequest Duration2MBMemory UsageGET ar/الدورات/{slug}Route
    • Booting (633ms)
    • Application (338ms)
    • 1 x Booting (65.01%)
      632.99ms
      1 x Application (34.74%)
      338.19ms
      14 templates were rendered
      • public.courses.show (resources/views/public/courses/show.blade.php)3bladefile
        Params
        0
        course
        1
        links
        2
        config
      • public.courses.partials.breadcrumbs (resources/views/public/courses/partials/breadcrumbs.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      • public.courses.partials.heading (resources/views/public/courses/partials/heading.blade.php)7bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
        6
        classes
      • public.courses.partials.details (resources/views/public/courses/partials/details.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      • public.courses.partials.breadcrumbs (resources/views/public/courses/partials/breadcrumbs.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      • public.courses.partials.heading (resources/views/public/courses/partials/heading.blade.php)7bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
        6
        classes
      • public.layouts.main (resources/views/public/layouts/main.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      • public.layouts.partials.meta (resources/views/public/layouts/partials/meta.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      • public.layouts.partials.navbar (resources/views/public/layouts/partials/navbar.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      • public.auth.profile.partials.links (resources/views/public/auth/profile/partials/links.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      • public.auth.profile.partials.link (resources/views/public/auth/profile/partials/link.blade.php)8bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
        6
        route
        7
        title
      • public.auth.profile.partials.link (resources/views/public/auth/profile/partials/link.blade.php)8bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
        6
        route
        7
        title
      • public.auth.profile.partials.link (resources/views/public/auth/profile/partials/link.blade.php)8bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
        6
        route
        7
        title
      • public.layouts.partials.flash-session (resources/views/public/layouts/partials/flash-session.blade.php)6bladefile
        Params
        0
        __env
        1
        app
        2
        errors
        3
        course
        4
        links
        5
        config
      uri
      GET ar/الدورات/{slug}
      middleware
      web, localize:ar
      controller
      App\Http\Controllers\CourseController@show
      as
      ar.courses.show
      namespace
      prefix
      /ar
      where
      file
      app/Http/Controllers/CourseController.php:17-35
      6 statements were executed11.83ms
      • select * from `courses` where `slug_ar` = 'computer-memory' limit 1
        8.22ms/app/Http/Controllers/CourseController.php:20corspedia
        Metadata
        Bindings
        • 0. computer-memory
        Backtrace
        • 17. /app/Http/Controllers/CourseController.php:20
        • 18. /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
        • 19. /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:43
        • 20. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:260
        • 21. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:205
      • update `courses` set `visitors` = `visitors` + 1, `courses`.`updated_at` = '2025-06-14 17:09:14' where `id` = 2138
        2.75ms/app/Http/Controllers/CourseController.php:21corspedia
        Metadata
        Bindings
        • 0. 2025-06-14 17:09:14
        • 1. 2138
        Backtrace
        • 17. /app/Http/Controllers/CourseController.php:21
        • 18. /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
        • 19. /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:43
        • 20. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:260
        • 21. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:205
      • select `id`, `name_en`, `name_ar`, `topic_id`, `slug_en`, `slug_ar` from `subjects` where `subjects`.`id` in (1)
        220μs/app/Http/Controllers/CourseController.php:23corspedia
        Metadata
        Backtrace
        • 20. /app/Http/Controllers/CourseController.php:23
        • 21. /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
        • 22. /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:43
        • 23. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:260
        • 24. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:205
      • select `id`, `name_en`, `name_ar`, `slug_en`, `slug_ar` from `topics` where `topics`.`id` in (1)
        180μs/app/Http/Controllers/CourseController.php:23corspedia
        Metadata
        Backtrace
        • 25. /app/Http/Controllers/CourseController.php:23
        • 26. /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
        • 27. /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:43
        • 28. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:260
        • 29. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:205
      • select * from `providers` where `providers`.`id` in (40) and `providers`.`deleted_at` is null
        210μs/app/Http/Controllers/CourseController.php:23corspedia
        Metadata
        Backtrace
        • 20. /app/Http/Controllers/CourseController.php:23
        • 21. /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
        • 22. /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:43
        • 23. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:260
        • 24. /vendor/laravel/framework/src/Illuminate/Routing/Route.php:205
      • select * from `html_files` where `html_files`.`id` = 2129 limit 1
        250μs/app/Models/Course.php:84corspedia
        Metadata
        Bindings
        • 0. 2129
        Backtrace
        • 21. /app/Models/Course.php:84
        • 28. view::public.courses.show:29
        • 30. /vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:125
        • 31. /vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php:58
        • 32. /vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php:72
      App\Models\HtmlFile
      1
      App\Models\Provider
      1
      App\Models\Topic
      1
      App\Models\Subject
      1
      App\Models\Course
      1
        _token
        MDb4QltusS4YxWFPTwsvhb36rkKGyKYFNLTE4KUm
        locale
        ar
        _previous
        array:1 [ "url" => "https://www.corspedia.com/ar/%D8%A7%D9%84%D8%AF%D9%88%D8%B1%D8%A7%D8%AA/comput...
        _flash
        array:2 [ "old" => [] "new" => [] ]
        PHPDEBUGBAR_STACK_DATA
        []
        path_info
        /ar/%D8%A7%D9%84%D8%AF%D9%88%D8%B1%D8%A7%D8%AA/computer-memory
        status_code
        200
        
        status_text
        OK
        format
        html
        content_type
        text/html; charset=UTF-8
        request_query
        []
        
        request_request
        []
        
        request_headers
        0 of 0
        array:24 [ "cf-ipcountry" => array:1 [ 0 => "US" ] "cf-connecting-ip" => array:1 [ 0 => "216.73.216.8" ] "cdn-loop" => array:1 [ 0 => "cloudflare; loops=1" ] "x-forwarded-proto" => array:1 [ 0 => "https" ] "x-forwarded-for" => array:1 [ 0 => "216.73.216.8" ] "sec-fetch-site" => array:1 [ 0 => "none" ] "accept" => array:1 [ 0 => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" ] "user-agent" => array:1 [ 0 => "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)" ] "upgrade-insecure-requests" => array:1 [ 0 => "1" ] "sec-ch-ua-platform" => array:1 [ 0 => ""Windows"" ] "sec-ch-ua-mobile" => array:1 [ 0 => "?0" ] "sec-ch-ua" => array:1 [ 0 => ""Chromium";v="130", "HeadlessChrome";v="130", "Not?A_Brand";v="99"" ] "cache-control" => array:1 [ 0 => "no-cache" ] "pragma" => array:1 [ 0 => "no-cache" ] "sec-fetch-dest" => array:1 [ 0 => "document" ] "cf-ray" => array:1 [ 0 => "94fb6f29f9cb6172-ORD" ] "accept-encoding" => array:1 [ 0 => "gzip, br" ] "priority" => array:1 [ 0 => "u=0, i" ] "sec-fetch-user" => array:1 [ 0 => "?1" ] "sec-fetch-mode" => array:1 [ 0 => "navigate" ] "cf-visitor" => array:1 [ 0 => "{"scheme":"https"}" ] "host" => array:1 [ 0 => "www.corspedia.com" ] "content-length" => array:1 [ 0 => "" ] "content-type" => array:1 [ 0 => "" ] ]
        request_server
        0 of 0
        array:50 [ "USER" => "www-data" "HOME" => "/var/www" "HTTP_CF_IPCOUNTRY" => "US" "HTTP_CF_CONNECTING_IP" => "216.73.216.8" "HTTP_CDN_LOOP" => "cloudflare; loops=1" "HTTP_X_FORWARDED_PROTO" => "https" "HTTP_X_FORWARDED_FOR" => "216.73.216.8" "HTTP_SEC_FETCH_SITE" => "none" "HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" "HTTP_USER_AGENT" => "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)" "HTTP_UPGRADE_INSECURE_REQUESTS" => "1" "HTTP_SEC_CH_UA_PLATFORM" => ""Windows"" "HTTP_SEC_CH_UA_MOBILE" => "?0" "HTTP_SEC_CH_UA" => ""Chromium";v="130", "HeadlessChrome";v="130", "Not?A_Brand";v="99"" "HTTP_CACHE_CONTROL" => "no-cache" "HTTP_PRAGMA" => "no-cache" "HTTP_SEC_FETCH_DEST" => "document" "HTTP_CF_RAY" => "94fb6f29f9cb6172-ORD" "HTTP_ACCEPT_ENCODING" => "gzip, br" "HTTP_PRIORITY" => "u=0, i" "HTTP_SEC_FETCH_USER" => "?1" "HTTP_SEC_FETCH_MODE" => "navigate" "HTTP_CF_VISITOR" => "{"scheme":"https"}" "HTTP_HOST" => "www.corspedia.com" "REDIRECT_STATUS" => "200" "SERVER_NAME" => "corspedia.com" "SERVER_PORT" => "443" "SERVER_ADDR" => "141.95.147.152" "REMOTE_USER" => "" "REMOTE_PORT" => "58148" "REMOTE_ADDR" => "172.69.7.3" "SERVER_SOFTWARE" => "nginx/1.18.0" "GATEWAY_INTERFACE" => "CGI/1.1" "HTTPS" => "on" "REQUEST_SCHEME" => "https" "SERVER_PROTOCOL" => "HTTP/2.0" "DOCUMENT_ROOT" => "/var/www/corspedia/public" "DOCUMENT_URI" => "/index.php" "REQUEST_URI" => "/ar/%D8%A7%D9%84%D8%AF%D9%88%D8%B1%D8%A7%D8%AA/computer-memory" "SCRIPT_NAME" => "/index.php" "CONTENT_LENGTH" => "" "CONTENT_TYPE" => "" "REQUEST_METHOD" => "GET" "QUERY_STRING" => "" "SCRIPT_FILENAME" => "/var/www/corspedia/public/index.php" "PATH_INFO" => "" "FCGI_ROLE" => "RESPONDER" "PHP_SELF" => "/index.php" "REQUEST_TIME_FLOAT" => 1749920954.1872 "REQUEST_TIME" => 1749920954 ]
        request_cookies
        []
        
        response_headers
        0 of 0
        array:5 [ "content-type" => array:1 [ 0 => "text/html; charset=UTF-8" ] "cache-control" => array:1 [ 0 => "no-cache, private" ] "date" => array:1 [ 0 => "Sat, 14 Jun 2025 17:09:14 GMT" ] "set-cookie" => array:2 [ 0 => "XSRF-TOKEN=eyJpdiI6Iko2NkcrTDFiZWhtM2lZYk56M3RkOUE9PSIsInZhbHVlIjoicGVyOGwwdmF0MHBzcXd1NG1qdlc1Y0w0T0d3aXNVUTMvbFB6WFNkRUJiQ0s1ampkaHozWnUvUHk1SjNCd1dNVVZLM2R2TWpuL0FJSkRCeld4d3lsU2x5NmlRenBxNHFuaTBveHdtOHlQMVp6L3QwbmFrbTBUNnQ5WWFtZ2lIR0EiLCJtYWMiOiJjMGRiNGJmZGU1MWMyMTdkYTQxOTA4Y2YyM2VjYzA4MjI5YjM2YWRhYjgxMGRjY2E3NDQ2NGZmZmEyNjBiOTU3IiwidGFnIjoiIn0%3D; expires=Sat, 14 Jun 2025 19:09:15 GMT; Max-Age=7200; path=/; samesite=laxXSRF-TOKEN=eyJpdiI6Iko2NkcrTDFiZWhtM2lZYk56M3RkOUE9PSIsInZhbHVlIjoicGVyOGwwdmF0MHBzcXd1NG1qdlc1Y0w0T0d3aXNVUTMvbFB6WFNkRUJiQ0s1ampkaHozWnUvUHk1SjNCd1dNVVZLM2R2T" 1 => "laravel_session=eyJpdiI6Im5RMEphSWhTZzJreHk4MkRBcENMZWc9PSIsInZhbHVlIjoiQlJwNExmUVZlNDJEeVZaUHVrc3ZOUGFOMmU5ZnZwTTk1cXZQUDlrWnpsbk5FcXAxR1QzN1I1bldOOHZBOE9hVVBqcUhQajhYQUVxa3J4aHI0NDBIajA4b1NHaXJ6YlhXMkdhUTlRNkdiaklsNkc1RmZndWJtYTB4ZUxUUFVCa0giLCJtYWMiOiJjMjU2Y2JmY2Q5OWI5ZDE4MzMwYTU5Yzc5NTlmNGY1YjcwZWY3ODc2YjgwYTIwOGUzZjYyM2NhZjdhNTA0Nzk5IiwidGFnIjoiIn0%3D; expires=Sat, 14 Jun 2025 19:09:15 GMT; Max-Age=7200; path=/; httponly; samesite=laxlaravel_session=eyJpdiI6Im5RMEphSWhTZzJreHk4MkRBcENMZWc9PSIsInZhbHVlIjoiQlJwNExmUVZlNDJEeVZaUHVrc3ZOUGFOMmU5ZnZwTTk1cXZQUDlrWnpsbk5FcXAxR1QzN1I1bldOOHZBOE9hVVBq" ] "Set-Cookie" => array:2 [ 0 => "XSRF-TOKEN=eyJpdi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k5FcXAxR1QzN1I1bldOOHZBOE9hVVBq" ] ]
        session_attributes
        0 of 0
        array:5 [ "_token" => "MDb4QltusS4YxWFPTwsvhb36rkKGyKYFNLTE4KUm" "locale" => "ar" "_previous" => array:1 [ "url" => "https://www.corspedia.com/ar/%D8%A7%D9%84%D8%AF%D9%88%D8%B1%D8%A7%D8%AA/computer-memory" ] "_flash" => array:2 [ "old" => [] "new" => [] ] "PHPDEBUGBAR_STACK_DATA" => [] ]