CINXE.COM
C dynamic memory allocation - Wikipedia
<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>C dynamic memory allocation - Wikipedia</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy", "wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"8368df83-68e1-426a-97e1-872c7eb73f16","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"C_dynamic_memory_allocation","wgTitle":"C dynamic memory allocation","wgCurRevisionId":1258413351,"wgRevisionId":1258413351,"wgArticleId":384289,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Articles with short description","Short description is different from Wikidata","Use dmy dates from May 2021","All articles with unsourced statements","Articles with unsourced statements from July 2022","Articles with example C++ code","All articles lacking reliable references","Articles lacking reliable references from November 2015","Articles with example C code","Memory management","Memory management software","C standard library","C++"], "wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"C_dynamic_memory_allocation","wgRelevantArticleId":384289,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgRedirectedFrom":"Malloc","wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":40000,"wgInternalRedirectTargetUrl":"/wiki/C_dynamic_memory_allocation","wgRelatedArticlesCompat":[],"wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage", "wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q1050390","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.pygments":"ready","ext.math.styles":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","jquery.makeCollapsible.styles":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready", "ext.wikimediaBadges":"ready"};RLPAGEMODULES=["mediawiki.action.view.redirect","ext.cite.ux-enhancements","ext.pygments.view","site","mediawiki.page.ready","jquery.makeCollapsible","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints","ext.quicksurveys.init","ext.growthExperiments.SuggestedEditSession","wikibase.sidebar.tracking"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&modules=ext.cite.styles%7Cext.math.styles%7Cext.pygments%2CwikimediaBadges%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cjquery.makeCollapsible.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&only=styles&skin=vector-2022"> <script async="" src="/w/load.php?lang=en&modules=startup&only=scripts&raw=1&skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&modules=site.styles&only=styles&skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.4"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="C dynamic memory allocation - Wikipedia"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//en.m.wikipedia.org/wiki/C_dynamic_memory_allocation"> <link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=C_dynamic_memory_allocation&action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png"> <link rel="icon" href="/static/favicon/wikipedia.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Wikipedia (en)"> <link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://en.wikipedia.org/wiki/C_dynamic_memory_allocation"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en"> <link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="//login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-C_dynamic_memory_allocation rootpage-C_dynamic_memory_allocation skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-contents" class="mw-list-item"><a href="/wiki/Wikipedia:Contents" title="Guides to browsing Wikipedia"><span>Contents</span></a></li><li id="n-currentevents" class="mw-list-item"><a href="/wiki/Portal:Current_events" title="Articles related to current events"><span>Current events</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Visit a randomly selected article [x]" accesskey="x"><span>Random article</span></a></li><li id="n-aboutsite" class="mw-list-item"><a href="/wiki/Wikipedia:About" title="Learn about Wikipedia and how it works"><span>About Wikipedia</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us" title="How to contact Wikipedia"><span>Contact us</span></a></li> </ul> </div> </div> <div id="p-interaction" class="vector-menu mw-portlet mw-portlet-interaction" > <div class="vector-menu-heading"> Contribute </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Help:Contents" title="Guidance on how to use and edit Wikipedia"><span>Help</span></a></li><li id="n-introduction" class="mw-list-item"><a href="/wiki/Help:Introduction" title="Learn how to edit Wikipedia"><span>Learn to edit</span></a></li><li id="n-portal" class="mw-list-item"><a href="/wiki/Wikipedia:Community_portal" title="The hub for editors"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes to Wikipedia [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_upload_wizard" title="Add images or other media for use on Wikipedia"><span>Upload file</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Main_Page" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Wikipedia" src="/static/images/mobile/copyright/wikipedia-wordmark-en.svg" style="width: 7.5em; height: 1.125em;"> <img class="mw-logo-tagline" alt="The Free Encyclopedia" src="/static/images/mobile/copyright/wikipedia-tagline-en.svg" width="117" height="13" style="width: 7.3125em; height: 0.8125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search Wikipedia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikipedia" aria-label="Search Wikipedia" autocapitalize="sentences" title="Search Wikipedia [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page's font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&utm_medium=sidebar&utm_campaign=C13_en.wikipedia.org&uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&returnto=C+dynamic+memory+allocation" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&returnto=C+dynamic+memory+allocation" title="You're encouraged to log in; however, it's not mandatory. [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Log in and more options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&utm_medium=sidebar&utm_campaign=C13_en.wikipedia.org&uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&returnto=C+dynamic+memory+allocation" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&returnto=C+dynamic+memory+allocation" title="You're encouraged to log in; however, it's not mandatory. [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">(Top)</div> </a> </li> <li id="toc-Rationale" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Rationale"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Rationale</span> </div> </a> <ul id="toc-Rationale-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Overview_of_functions" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Overview_of_functions"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Overview of functions</span> </div> </a> <button aria-controls="toc-Overview_of_functions-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Overview of functions subsection</span> </button> <ul id="toc-Overview_of_functions-sublist" class="vector-toc-list"> <li id="toc-Differences_between_malloc()_and_calloc()" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Differences_between_malloc()_and_calloc()"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1</span> <span>Differences between malloc() and calloc()</span> </div> </a> <ul id="toc-Differences_between_malloc()_and_calloc()-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Usage_example" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Usage_example"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Usage example</span> </div> </a> <ul id="toc-Usage_example-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Type_safety" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Type_safety"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Type safety</span> </div> </a> <button aria-controls="toc-Type_safety-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Type safety subsection</span> </button> <ul id="toc-Type_safety-sublist" class="vector-toc-list"> <li id="toc-Advantages_to_casting" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Advantages_to_casting"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1</span> <span>Advantages to casting</span> </div> </a> <ul id="toc-Advantages_to_casting-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Disadvantages_to_casting" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Disadvantages_to_casting"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2</span> <span>Disadvantages to casting</span> </div> </a> <ul id="toc-Disadvantages_to_casting-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Common_errors" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Common_errors"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>Common errors</span> </div> </a> <ul id="toc-Common_errors-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Implementations" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Implementations"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Implementations</span> </div> </a> <button aria-controls="toc-Implementations-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Implementations subsection</span> </button> <ul id="toc-Implementations-sublist" class="vector-toc-list"> <li id="toc-Heap-based" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Heap-based"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.1</span> <span>Heap-based</span> </div> </a> <ul id="toc-Heap-based-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-dlmalloc_and_ptmalloc" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#dlmalloc_and_ptmalloc"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.2</span> <span>dlmalloc and ptmalloc</span> </div> </a> <ul id="toc-dlmalloc_and_ptmalloc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-FreeBSD's_and_NetBSD's_jemalloc" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#FreeBSD's_and_NetBSD's_jemalloc"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.3</span> <span>FreeBSD's and NetBSD's jemalloc</span> </div> </a> <ul id="toc-FreeBSD's_and_NetBSD's_jemalloc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-OpenBSD's_malloc" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#OpenBSD's_malloc"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.4</span> <span>OpenBSD's malloc</span> </div> </a> <ul id="toc-OpenBSD's_malloc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Hoard_malloc" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Hoard_malloc"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.5</span> <span>Hoard malloc</span> </div> </a> <ul id="toc-Hoard_malloc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-mimalloc" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#mimalloc"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.6</span> <span>mimalloc</span> </div> </a> <ul id="toc-mimalloc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Thread-caching_malloc_(tcmalloc)" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Thread-caching_malloc_(tcmalloc)"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.7</span> <span>Thread-caching malloc (tcmalloc)</span> </div> </a> <ul id="toc-Thread-caching_malloc_(tcmalloc)-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-In-kernel" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#In-kernel"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.8</span> <span>In-kernel</span> </div> </a> <ul id="toc-In-kernel-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Overriding_malloc" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Overriding_malloc"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>Overriding malloc</span> </div> </a> <ul id="toc-Overriding_malloc-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Allocation_size_limits" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Allocation_size_limits"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>Allocation size limits</span> </div> </a> <ul id="toc-Allocation_size_limits-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Extensions_and_alternatives" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Extensions_and_alternatives"> <div class="vector-toc-text"> <span class="vector-toc-numb">9</span> <span>Extensions and alternatives</span> </div> </a> <ul id="toc-Extensions_and_alternatives-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-See_also" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#See_also"> <div class="vector-toc-text"> <span class="vector-toc-numb">10</span> <span>See also</span> </div> </a> <ul id="toc-See_also-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-References" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#References"> <div class="vector-toc-text"> <span class="vector-toc-numb">11</span> <span>References</span> </div> </a> <ul id="toc-References-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-External_links" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#External_links"> <div class="vector-toc-text"> <span class="vector-toc-numb">12</span> <span>External links</span> </div> </a> <ul id="toc-External_links-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">C dynamic memory allocation</span></h1> <div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" > <input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="Go to an article in another language. Available in 9 languages" > <label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-9" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span> <span class="vector-dropdown-label-text">9 languages</span> </label> <div class="vector-dropdown-content"> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="interlanguage-link interwiki-ca mw-list-item"><a href="https://ca.wikipedia.org/wiki/Assignaci%C3%B3_de_mem%C3%B2ria_din%C3%A0mica_en_C" title="Assignació de memòria dinàmica en C – Catalan" lang="ca" hreflang="ca" data-title="Assignació de memòria dinàmica en C" data-language-autonym="Català" data-language-local-name="Catalan" class="interlanguage-link-target"><span>Català</span></a></li><li class="interlanguage-link interwiki-cs mw-list-item"><a href="https://cs.wikipedia.org/wiki/Dynamick%C3%A1_alokace_pam%C4%9Bti_v_jazyce_C" title="Dynamická alokace paměti v jazyce C – Czech" lang="cs" hreflang="cs" data-title="Dynamická alokace paměti v jazyce C" data-language-autonym="Čeština" data-language-local-name="Czech" class="interlanguage-link-target"><span>Čeština</span></a></li><li class="interlanguage-link interwiki-fa mw-list-item"><a href="https://fa.wikipedia.org/wiki/%D8%A7%D8%AE%D8%AA%D8%B5%D8%A7%D8%B5_%D8%AD%D8%A7%D9%81%D8%B8%D9%87_%D9%BE%D9%88%DB%8C%D8%A7_%D8%AF%D8%B1_%D8%B3%DB%8C" title="اختصاص حافظه پویا در سی – Persian" lang="fa" hreflang="fa" data-title="اختصاص حافظه پویا در سی" data-language-autonym="فارسی" data-language-local-name="Persian" class="interlanguage-link-target"><span>فارسی</span></a></li><li class="interlanguage-link interwiki-ko mw-list-item"><a href="https://ko.wikipedia.org/wiki/C_%EB%8F%99%EC%A0%81_%EB%A9%94%EB%AA%A8%EB%A6%AC_%ED%95%A0%EB%8B%B9" title="C 동적 메모리 할당 – Korean" lang="ko" hreflang="ko" data-title="C 동적 메모리 할당" data-language-autonym="한국어" data-language-local-name="Korean" class="interlanguage-link-target"><span>한국어</span></a></li><li class="interlanguage-link interwiki-pt mw-list-item"><a href="https://pt.wikipedia.org/wiki/Aloca%C3%A7%C3%A3o_din%C3%A2mica_de_mem%C3%B3ria_em_C" title="Alocação dinâmica de memória em C – Portuguese" lang="pt" hreflang="pt" data-title="Alocação dinâmica de memória em C" data-language-autonym="Português" data-language-local-name="Portuguese" class="interlanguage-link-target"><span>Português</span></a></li><li class="interlanguage-link interwiki-simple mw-list-item"><a href="https://simple.wikipedia.org/wiki/C_dynamic_memory_allocation" title="C dynamic memory allocation – Simple English" lang="en-simple" hreflang="en-simple" data-title="C dynamic memory allocation" data-language-autonym="Simple English" data-language-local-name="Simple English" class="interlanguage-link-target"><span>Simple English</span></a></li><li class="interlanguage-link interwiki-tr mw-list-item"><a href="https://tr.wikipedia.org/wiki/C_dinamik_bellek_y%C3%B6netimi_ve_tahsisi" title="C dinamik bellek yönetimi ve tahsisi – Turkish" lang="tr" hreflang="tr" data-title="C dinamik bellek yönetimi ve tahsisi" data-language-autonym="Türkçe" data-language-local-name="Turkish" class="interlanguage-link-target"><span>Türkçe</span></a></li><li class="interlanguage-link interwiki-uk mw-list-item"><a href="https://uk.wikipedia.org/wiki/%D0%94%D0%B8%D0%BD%D0%B0%D0%BC%D1%96%D1%87%D0%BD%D0%B8%D0%B9_%D1%80%D0%BE%D0%B7%D0%BF%D0%BE%D0%B4%D1%96%D0%BB_%D0%BF%D0%B0%D0%BC%27%D1%8F%D1%82%D1%96_%D0%B2_C" title="Динамічний розподіл пам'яті в C – Ukrainian" lang="uk" hreflang="uk" data-title="Динамічний розподіл пам'яті в C" data-language-autonym="Українська" data-language-local-name="Ukrainian" class="interlanguage-link-target"><span>Українська</span></a></li><li class="interlanguage-link interwiki-zh mw-list-item"><a href="https://zh.wikipedia.org/wiki/C%E5%8A%A8%E6%80%81%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D" title="C动态内存分配 – Chinese" lang="zh" hreflang="zh" data-title="C动态内存分配" data-language-autonym="中文" data-language-local-name="Chinese" class="interlanguage-link-target"><span>中文</span></a></li> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-edit wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q1050390#sitelinks-wikipedia" title="Edit interlanguage links" class="wbc-editpage">Edit links</a></span></div> </div> </div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/C_dynamic_memory_allocation" title="View the content page [c]" accesskey="c"><span>Article</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Talk:C_dynamic_memory_allocation" rel="discussion" title="Discuss improvements to the content page [t]" accesskey="t"><span>Talk</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/C_dynamic_memory_allocation"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=C_dynamic_memory_allocation&action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/C_dynamic_memory_allocation"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=C_dynamic_memory_allocation&action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/C_dynamic_memory_allocation" title="List of all English Wikipedia pages containing links to this page [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/C_dynamic_memory_allocation" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_Upload_Wizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=C_dynamic_memory_allocation&oldid=1258413351" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=C_dynamic_memory_allocation&action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&page=C_dynamic_memory_allocation&id=1258413351&wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FC_dynamic_memory_allocation"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrCode&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FC_dynamic_memory_allocation"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&page=C_dynamic_memory_allocation&action=show-download-screen" title="Download this page as a PDF file"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=C_dynamic_memory_allocation&printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q1050390" title="Structured data on this page hosted by Wikidata [g]" accesskey="g"><span>Wikidata item</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> </div> <div id="siteSub" class="noprint">From Wikipedia, the free encyclopedia</div> </div> <div id="contentSub"><div id="mw-content-subtitle"><span class="mw-redirectedfrom">(Redirected from <a href="/w/index.php?title=Malloc&redirect=no" class="mw-redirect" title="Malloc">Malloc</a>)</span></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">Dynamic memory management in the C programming language</div> <style data-mw-deduplicate="TemplateStyles:r1236090951">.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}</style><div role="note" class="hatnote navigation-not-searchable">"Malloc" redirects here. For Mallock, see <a href="/wiki/Mallock" title="Mallock">Mallock</a>.</div> <p class="mw-empty-elt"> </p> <style data-mw-deduplicate="TemplateStyles:r1129693374">.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}</style><style data-mw-deduplicate="TemplateStyles:r1246091330">.mw-parser-output .sidebar{width:22em;float:right;clear:right;margin:0.5em 0 1em 1em;background:var(--background-color-neutral-subtle,#f8f9fa);border:1px solid var(--border-color-base,#a2a9b1);padding:0.2em;text-align:center;line-height:1.4em;font-size:88%;border-collapse:collapse;display:table}body.skin-minerva .mw-parser-output .sidebar{display:table!important;float:right!important;margin:0.5em 0 1em 1em!important}.mw-parser-output .sidebar-subgroup{width:100%;margin:0;border-spacing:0}.mw-parser-output .sidebar-left{float:left;clear:left;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-none{float:none;clear:both;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-outer-title{padding:0 0.4em 0.2em;font-size:125%;line-height:1.2em;font-weight:bold}.mw-parser-output .sidebar-top-image{padding:0.4em}.mw-parser-output .sidebar-top-caption,.mw-parser-output .sidebar-pretitle-with-top-image,.mw-parser-output .sidebar-caption{padding:0.2em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-pretitle{padding:0.4em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-title,.mw-parser-output .sidebar-title-with-pretitle{padding:0.2em 0.8em;font-size:145%;line-height:1.2em}.mw-parser-output .sidebar-title-with-pretitle{padding:0.1em 0.4em}.mw-parser-output .sidebar-image{padding:0.2em 0.4em 0.4em}.mw-parser-output .sidebar-heading{padding:0.1em 0.4em}.mw-parser-output .sidebar-content{padding:0 0.5em 0.4em}.mw-parser-output .sidebar-content-with-subgroup{padding:0.1em 0.4em 0.2em}.mw-parser-output .sidebar-above,.mw-parser-output .sidebar-below{padding:0.3em 0.8em;font-weight:bold}.mw-parser-output .sidebar-collapse .sidebar-above,.mw-parser-output .sidebar-collapse .sidebar-below{border-top:1px solid #aaa;border-bottom:1px solid #aaa}.mw-parser-output .sidebar-navbar{text-align:right;font-size:115%;padding:0 0.4em 0.4em}.mw-parser-output .sidebar-list-title{padding:0 0.4em;text-align:left;font-weight:bold;line-height:1.6em;font-size:105%}.mw-parser-output .sidebar-list-title-c{padding:0 0.4em;text-align:center;margin:0 3.3em}@media(max-width:640px){body.mediawiki .mw-parser-output .sidebar{width:100%!important;clear:both;float:none!important;margin-left:0!important;margin-right:0!important}}body.skin--responsive .mw-parser-output .sidebar a>img{max-width:none!important}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media print{body.ns-0 .mw-parser-output .sidebar{display:none!important}}</style><style data-mw-deduplicate="TemplateStyles:r1238254908">.mw-parser-output .c-standard-library .sidebar-content{text-align:left}</style><style data-mw-deduplicate="TemplateStyles:r886049734">.mw-parser-output .monospaced{font-family:monospace,monospace}</style><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><table class="sidebar nomobile nowraplinks c-standard-library"><tbody><tr><th class="sidebar-title"><a href="/wiki/C_standard_library" title="C standard library">C standard library</a> (libc)</th></tr><tr><th class="sidebar-heading"> General topics</th></tr><tr><td class="sidebar-content"> <ul><li><a href="/wiki/C_data_types" title="C data types">Data types</a></li> <li><a href="/wiki/C_character_classification" title="C character classification">Character classification</a></li> <li><a href="/wiki/C_string_handling" title="C string handling">Strings</a></li> <li><a href="/wiki/C_mathematical_functions" title="C mathematical functions">Mathematics</a></li> <li><a href="/wiki/C_file_input/output" title="C file input/output">File input/output</a></li> <li><a href="/wiki/C_date_and_time_functions" title="C date and time functions">Date/time</a></li> <li><a href="/wiki/C_localization_functions" title="C localization functions">Localization</a></li> <li><a class="mw-selflink selflink">Memory allocation</a></li> <li><a href="/wiki/C_process_control" title="C process control">Process control</a></li> <li><a href="/wiki/C_signal_handling" title="C signal handling">Signals</a></li> <li><a href="/wiki/C_alternative_tokens" title="C alternative tokens">Alternative tokens</a></li></ul></td> </tr><tr><th class="sidebar-heading"> Miscellaneous headers</th></tr><tr><td class="sidebar-content"> <ul><li><span class="monospaced"><<a href="/wiki/Assert.h" title="Assert.h">assert.h</a>></span></li> <li><span class="monospaced"><<a href="/wiki/Errno.h" title="Errno.h">errno.h</a>></span></li> <li><span class="monospaced"><<a href="/wiki/Setjmp.h" title="Setjmp.h">setjmp.h</a>></span></li> <li><span class="monospaced"><<a href="/wiki/Stdarg.h" title="Stdarg.h">stdarg.h</a>></span></li></ul></td> </tr><tr><td class="sidebar-navbar"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><style data-mw-deduplicate="TemplateStyles:r1239400231">.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}</style><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:C_standard_library" title="Template:C standard library"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:C_standard_library" title="Template talk:C standard library"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:C_standard_library" title="Special:EditPage/Template:C standard library"><abbr title="Edit this template">e</abbr></a></li></ul></div></td></tr></tbody></table> <p><b>C dynamic memory allocation</b> refers to performing <a href="/wiki/Manual_memory_management" title="Manual memory management">manual memory management</a> for <a href="/wiki/Dynamic_memory_allocation" class="mw-redirect" title="Dynamic memory allocation">dynamic memory allocation</a> in the <a href="/wiki/C_(programming_language)" title="C (programming language)">C programming language</a> via a group of functions in the <a href="/wiki/C_standard_library" title="C standard library">C standard library</a>, namely <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">malloc</span>, <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">realloc</span>, <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">calloc</span>, <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">aligned_alloc</span> and <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">free</span>.<sup id="cite_ref-c99_1-0" class="reference"><a href="#cite_note-c99-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> </p><p>The <a href="/wiki/C%2B%2B" title="C++">C++</a> programming language includes these functions; however, the operators <a href="/wiki/New_and_delete_(C%2B%2B)" title="New and delete (C++)"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">new</span> and <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">delete</span></a> provide similar functionality and are recommended by that language's authors.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> Still, there are several situations in which using <code>new</code>/<code>delete</code> is not applicable, such as garbage collection code or performance-sensitive code, and a combination of <code>malloc</code> and placement <code>new</code> may be required instead of the higher-level <code>new</code> operator. </p><p>Many different implementations of the actual memory allocation mechanism, used by <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r886049734"><span class="monospaced">malloc</span>, are available. Their performance varies in both execution time and required memory. </p> <meta property="mw:PageProp/toc" /> <div class="mw-heading mw-heading2"><h2 id="Rationale">Rationale</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=1" title="Edit section: Rationale"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The <a href="/wiki/C_(programming_language)" title="C (programming language)">C programming language</a> manages memory <a href="/wiki/Static_memory_allocation" class="mw-redirect" title="Static memory allocation">statically</a>, <a href="/wiki/Automatic_memory_allocation" class="mw-redirect" title="Automatic memory allocation">automatically</a>, or <a href="/wiki/Dynamic_memory_allocation" class="mw-redirect" title="Dynamic memory allocation">dynamically</a>. Static-duration variables are allocated in main memory, usually along with the executable code of the program, and persist for the lifetime of the program; automatic-duration variables are allocated on the <a href="/wiki/Call_stack" title="Call stack">stack</a> and come and go as functions are called and return. For static-duration and automatic-duration variables, the size of the allocation must be <a href="/wiki/Compile-time" class="mw-redirect" title="Compile-time">compile-time</a> constant (except for the case of variable-length automatic arrays<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>). If the required size is not known until <a href="/wiki/Run_time_(program_lifecycle_phase)" class="mw-redirect" title="Run time (program lifecycle phase)">run-time</a> (for example, if data of arbitrary size is being read from the user or from a disk file), then using fixed-size data objects is inadequate. </p><p>The lifetime of allocated memory can also cause concern. Neither static- nor automatic-duration memory is adequate for all situations. Automatic-allocated data cannot persist across multiple function calls, while static data persists for the life of the program whether it is needed or not. In many situations the programmer requires greater flexibility in managing the lifetime of allocated memory. </p><p>These limitations are avoided by using <a href="/wiki/Dynamic_memory_allocation" class="mw-redirect" title="Dynamic memory allocation">dynamic memory allocation</a>, in which memory is more explicitly (but more flexibly) managed, typically by allocating it from the <span class="citation-needed-content" style="padding-left:0.1em; padding-right:0.1em; color:var(--color-subtle, #54595d); border:1px solid var(--border-color-subtle, #c8ccd1);"><i>free store</i> (informally called the "heap"),</span><sup class="noprint Inline-Template Template-Fact" style="margin-left:0.1em; white-space:nowrap;">[<i><a href="/wiki/Wikipedia:Citation_needed" title="Wikipedia:Citation needed"><span title="In my experience 'heap' is almost exclusively used in a C context. While free store is used in C++ context for the new/delete operators. (July 2022)">citation needed</span></a></i>]</sup> an area of memory structured for this purpose. In C, the library function <code>malloc</code> is used to allocate a block of memory on the heap. The program accesses this block of memory via a <a href="/wiki/Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> that <code>malloc</code> returns. When the memory is no longer needed, the pointer is passed to <code>free</code> which deallocates the memory so that it can be used for other purposes. </p><p>The original description of C indicated that <code>calloc</code> and <code>cfree</code> were in the standard library, but not <code>malloc</code>. Code for a simple model implementation of a storage manager for <a href="/wiki/Unix" title="Unix">Unix</a> was given with <code>alloc</code> and <code>free</code> as the user interface functions, and using the <code><a href="/wiki/Sbrk" title="Sbrk">sbrk</a></code> system call to request memory from the operating system.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> The 6th Edition Unix documentation gives <code>alloc</code> and <code>free</code> as the low-level memory allocation functions.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> The <code>malloc</code> and <code>free</code> routines in their modern form are completely described in the 7th Edition Unix manual.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup> </p><p>Some platforms provide library or <a href="/wiki/Intrinsic_function" title="Intrinsic function">intrinsic function</a> calls which allow run-time dynamic allocation from the C stack rather than the heap (e.g. <code>alloca()</code><sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>). This memory is automatically freed when the calling function ends. </p> <div class="mw-heading mw-heading2"><h2 id="Overview_of_functions">Overview of functions</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=2" title="Edit section: Overview of functions"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The C dynamic memory allocation functions are defined in <code>stdlib.h</code> header (<code>cstdlib</code> header in C++).<sup id="cite_ref-c99_1-1" class="reference"><a href="#cite_note-c99-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> </p> <table class="wikitable"> <tbody><tr> <th>Function </th> <th>Description </th></tr> <tr> <td><span class="anchor" id="malloc"></span><code class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><span class="n">malloc</span></code> </td> <td>allocates the specified number of bytes </td></tr> <tr> <td><span class="anchor" id="aligned_alloc"></span><code class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><span class="n">aligned_alloc</span></code> </td> <td>allocates the specified number of bytes at the specified alignment </td></tr> <tr> <td><span class="anchor" id="realloc"></span><code class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><span class="n">realloc</span></code> </td> <td>increases or decreases the size of the specified block of memory, moving it if necessary </td></tr> <tr> <td><span class="anchor" id="calloc"></span><code class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><span class="n">calloc</span></code> </td> <td>allocates the specified number of bytes and initializes them to zero </td></tr> <tr> <td><span class="anchor" id="free"></span><code class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><span class="n">free</span></code> </td> <td>releases the specified block of memory back to the system </td></tr></tbody></table> <div class="mw-heading mw-heading3"><h3 id="Differences_between_malloc()_and_calloc()"><span id="Differences_between_malloc.28.29_and_calloc.28.29"></span>Differences between <code>malloc()</code> and <code>calloc()</code></h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=3" title="Edit section: Differences between malloc() and calloc()"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><code>malloc()</code> takes a single argument (the amount of memory to allocate in bytes), while <code>calloc()</code> takes two arguments — the number of elements and the size of each element.</li> <li><code>malloc()</code> only allocates memory, while <code>calloc()</code> allocates and sets the bytes in the allocated region to zero.<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup></li></ul> <div class="mw-heading mw-heading2"><h2 id="Usage_example">Usage example</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=4" title="Edit section: Usage example"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Creating an <a href="/wiki/Array_data_structure" class="mw-redirect" title="Array data structure">array</a> of ten integers with automatic scope is straightforward in C: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="n">array</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span> </pre></div> <p>However, the size of the array is fixed at compile time. If one wishes to allocate a similar array dynamically without using a <a href="/wiki/Variable-length_array" title="Variable-length array">variable-length array</a>, which is not guaranteed to be supported in all <a href="/wiki/C11_(C_standard_revision)" title="C11 (C standard revision)">C11</a> implementations, the following code can be used: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">array</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="mi">10</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span> </pre></div> <p>This computes the number of bytes that ten integers occupy in memory, then requests that many bytes from <code>malloc</code> and assigns the result to a <a href="/wiki/Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> named <code>array</code> (due to C syntax, pointers and arrays can be used interchangeably in some situations). </p><p>Because <code>malloc</code> might not be able to service the request, it might return a <a href="/wiki/Null_pointer" title="Null pointer">null pointer</a> and it is <a href="/wiki/Coding_best_practices" title="Coding best practices">good programming practice</a> to check for this: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">array</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="mi">10</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span> <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">array</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"malloc failed</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">-1</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>When the program no longer needs the <a href="/wiki/Dynamic_array" title="Dynamic array">dynamic array</a>, it must eventually call <code>free</code> to return the memory it occupies to the free store: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="n">free</span><span class="p">(</span><span class="n">array</span><span class="p">);</span> </pre></div> <p>The memory set aside by <code>malloc</code> is not <a href="/wiki/Initialization_(programming)" title="Initialization (programming)">initialized</a> and may contain <a href="/wiki/Cruft" title="Cruft">cruft</a>: the remnants of previously used and discarded data. After allocation with <code>malloc</code>, elements of the array are <a href="/wiki/Uninitialized_variable" title="Uninitialized variable">uninitialized variables</a>. The command <code>calloc</code> will return an allocation that has already been cleared: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">array</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">calloc</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span> </pre></div> <p>With realloc we can resize the amount of memory a pointer points to. For example, if we have a pointer acting as an array of size <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> and we want to change it to an array of size <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span>, we can use realloc. </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span> <span class="n">arr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span> <span class="n">arr</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span> <span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">realloc</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span> <span class="n">arr</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="p">;</span> </pre></div> <p>Note that realloc must be assumed to have changed the base address of the block (i.e. if it has failed to extend the size of the original block, and has therefore allocated a new larger block elsewhere and copied the old contents into it). Therefore, any pointers to addresses within the original block are also no longer valid. </p> <div class="mw-heading mw-heading2"><h2 id="Type_safety">Type safety</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=5" title="Edit section: Type safety"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><code>malloc</code> returns a <a href="/wiki/Void_pointer" class="mw-redirect" title="Void pointer">void pointer</a> (<code>void *</code>), which indicates that it is a pointer to a region of unknown data type. The use of casting is required in C++ due to the strong type system, whereas this is not the case in C. One may "cast" (see <a href="/wiki/Type_conversion" title="Type conversion">type conversion</a>) this pointer to a specific type: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="n">ptr2</span><span class="p">;</span> <span class="n">ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="mi">10</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">ptr</span><span class="p">));</span><span class="w"> </span><span class="cm">/* without a cast */</span> <span class="n">ptr2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="mi">10</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">ptr</span><span class="p">));</span><span class="w"> </span><span class="cm">/* with a cast */</span> </pre></div> <p>There are advantages and disadvantages to performing such a cast. </p> <div class="mw-heading mw-heading3"><h3 id="Advantages_to_casting">Advantages to casting</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=6" title="Edit section: Advantages to casting"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li>Including the cast may allow a C program or function to compile as C++.</li> <li>The cast allows for <a href="/wiki/ANSI_C" title="ANSI C">pre-1989 versions</a> of <code>malloc</code> that originally returned a <code>char *</code>.<sup id="cite_ref-Cprog_malloc_12-0" class="reference"><a href="#cite_note-Cprog_malloc-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup></li> <li>Casting can help the developer identify inconsistencies in type sizing should the destination pointer type change, particularly if the pointer is declared far from the <code>malloc()</code> call (although modern compilers and static analysers can warn on such behaviour without requiring the cast<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>).</li></ul> <div class="mw-heading mw-heading3"><h3 id="Disadvantages_to_casting">Disadvantages to casting</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=7" title="Edit section: Disadvantages to casting"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li>Under the C standard, the cast is redundant.</li> <li>Adding the cast may mask failure to include the header <code>stdlib.h</code>, in which the <a href="/wiki/Function_prototype" title="Function prototype">function prototype</a> for <code>malloc</code> is found.<sup id="cite_ref-Cprog_malloc_12-1" class="reference"><a href="#cite_note-Cprog_malloc-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup> In the absence of a prototype for <code>malloc</code>, the C90 standard requires that the C compiler assume <code>malloc</code> returns an <code>int</code>. If there is no cast, C90 requires a diagnostic when this integer is assigned to the pointer; however, with the cast, this diagnostic would not be produced, hiding a bug. On certain architectures and data models (such as LP64 on 64-bit systems, where <code>long</code> and pointers are 64-bit and <code>int</code> is 32-bit), this error can actually result in undefined behaviour, as the implicitly declared <code>malloc</code> returns a 32-bit value whereas the actually defined function returns a 64-bit value. Depending on calling conventions and memory layout, this may result in <a href="/wiki/Stack_smashing" class="mw-redirect" title="Stack smashing">stack smashing</a>. This issue is less likely to go unnoticed in modern compilers, as C99 does not permit implicit declarations, so the compiler must produce a diagnostic even if it does assume <code>int</code> return.</li> <li>If the type of the pointer is changed at its declaration, one may also need to change all lines where <code>malloc</code> is called and cast.</li></ul> <div class="mw-heading mw-heading2"><h2 id="Common_errors">Common errors</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=8" title="Edit section: Common errors"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The improper use of dynamic memory allocation can frequently be a source of bugs. These can include security bugs or program crashes, most often due to <a href="/wiki/Segmentation_fault" title="Segmentation fault">segmentation faults</a>. </p><p>Most common errors are as follows:<sup id="cite_ref-15" class="reference"><a href="#cite_note-15"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup> </p> <dl><dt>Not checking for allocation failures</dt> <dd>Memory allocation is not guaranteed to succeed, and may instead return a null pointer. Using the returned value, without checking if the allocation is successful, invokes <a href="/wiki/Undefined_behavior" title="Undefined behavior">undefined behavior</a>. This usually leads to crash (due to the resulting segmentation fault on the null pointer dereference), but there is no guarantee that a crash will happen so relying on that can also lead to problems.</dd> <dt>Memory leaks</dt> <dd>Failure to deallocate memory using <code>free</code> leads to buildup of non-reusable memory, which is no longer used by the program. This wastes memory resources and can lead to allocation failures when these resources are exhausted. <span class="anchor" id="Use_after_free"></span></dd> <dt>Logical errors</dt> <dd>All allocations must follow the same pattern: allocation using <code>malloc</code>, usage to store data, deallocation using <code>free</code>. Failures to adhere to this pattern, such as memory usage after a call to <code>free</code> (<a href="/wiki/Dangling_pointer" title="Dangling pointer">dangling pointer</a>) or before a call to <code>malloc</code> (<a href="/wiki/Wild_pointer" class="mw-redirect" title="Wild pointer">wild pointer</a>), calling <code>free</code> twice ("double free"), etc., usually causes a segmentation fault and results in a crash of the program. These errors can be transient and hard to debug – for example, freed memory is usually not immediately reclaimed by the OS, and thus dangling pointers may persist for a while and appear to work.</dd></dl> <p>In addition, as an interface that precedes ANSI C standardization, <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">malloc</code> and its associated functions have behaviors that were intentionally left to the implementation to define for themselves. One of them is the zero-length allocation, which is more of a problem with <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">realloc</code> since it is more common to resize to zero.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup> Although both <a href="/wiki/POSIX" title="POSIX">POSIX</a> and the <a href="/wiki/Single_Unix_Specification" class="mw-redirect" title="Single Unix Specification">Single Unix Specification</a> require proper handling of 0-size allocations by either returning <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">NULL</code> or something else that can be safely freed,<sup id="cite_ref-17" class="reference"><a href="#cite_note-17"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup> not all platforms are required to abide by these rules. Among the many double-free errors that it has led to, the 2019 <a href="/wiki/WhatsApp" title="WhatsApp">WhatsApp</a> RCE was especially prominent.<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">[</span>18<span class="cite-bracket">]</span></a></sup> A way to wrap these functions to make them safer is by simply checking for 0-size allocations and turning them into those of size 1. (Returning <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">NULL</code> has its own problems: it otherwise indicates an out-of-memory failure. In the case of <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">realloc</code> it would have signaled that the original memory was not moved and freed, which again is not the case for size 0, leading to the double-free.)<sup id="cite_ref-19" class="reference"><a href="#cite_note-19"><span class="cite-bracket">[</span>19<span class="cite-bracket">]</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="Implementations">Implementations</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=9" title="Edit section: Implementations"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The implementation of memory management depends greatly upon operating system and architecture. Some operating systems supply an allocator for malloc, while others supply functions to control certain regions of data. The same dynamic memory allocator is often used to implement both <code>malloc</code> and the operator <code>new</code> in <a href="/wiki/C%2B%2B" title="C++">C++</a>.<sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">[</span>20<span class="cite-bracket">]</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Heap-based">Heap-based</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=10" title="Edit section: Heap-based"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236090951"><div role="note" class="hatnote navigation-not-searchable">See also: <a href="/wiki/Sbrk" title="Sbrk">sbrk</a></div> <p>Implementation of legacy allocators was commonly done using the <a href="/wiki/Data_segment#Heap" title="Data segment">heap segment</a>. The allocator would usually expand and contract the heap to fulfill allocation requests. </p><p>The heap method suffers from a few inherent flaws: </p> <ul><li>A linear allocator can only shrink if the last allocation is released. Even if largely unused, the heap can get "stuck" at a very large size because of a small but long-lived allocation at its tip which could waste any amount of address space, although some allocators on some systems may be able to release entirely empty intermediate pages to the OS.</li> <li>A linear allocator is sensitive to <a href="/wiki/Fragmentation_(computer)" class="mw-redirect" title="Fragmentation (computer)">fragmentation</a>. A good allocator will attempt to track and reuse free slots through the entire heap, but as allocation sizes and lifetimes get mixed it can be difficult and expensive to find or coalesce free segments large enough to hold new allocation requests.</li> <li>A linear allocator has extremely poor concurrency characteristics, as the heap segment is per-process every thread has to synchronise on allocation, and concurrent allocations from threads which may have very different work loads amplifies the previous two issues.</li></ul> <p><span class="anchor" id="dlmalloc"></span> </p> <div class="mw-heading mw-heading3"><h3 id="dlmalloc_and_ptmalloc">dlmalloc and ptmalloc<span class="anchor" id="dlmalloc"></span></h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=11" title="Edit section: dlmalloc and ptmalloc"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Doug_Lea" title="Doug Lea">Doug Lea</a> has developed the <a href="/wiki/Public_domain" title="Public domain">public domain</a> dlmalloc ("Doug Lea's Malloc") as a general-purpose allocator, starting in 1987. The <a href="/wiki/GNU_C_library" class="mw-redirect" title="GNU C library">GNU C library</a> (glibc) is derived from Wolfram Gloger's ptmalloc ("pthreads malloc"), a fork of dlmalloc with threading-related improvements.<sup id="cite_ref-21" class="reference"><a href="#cite_note-21"><span class="cite-bracket">[</span>21<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-phrack-57-8_22-0" class="reference"><a href="#cite_note-phrack-57-8-22"><span class="cite-bracket">[</span>22<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-23" class="reference"><a href="#cite_note-23"><span class="cite-bracket">[</span>23<span class="cite-bracket">]</span></a></sup> As of November 2023, the latest version of dlmalloc is version 2.8.6 from August 2012.<sup id="cite_ref-dlmalloc_24-0" class="reference"><a href="#cite_note-dlmalloc-24"><span class="cite-bracket">[</span>24<span class="cite-bracket">]</span></a></sup> </p><p>dlmalloc is a boundary tag allocator. Memory on the <a href="/wiki/Heap_memory" class="mw-redirect" title="Heap memory">heap</a> is allocated as "chunks", an 8-byte <a href="/wiki/Data_structure_alignment" title="Data structure alignment">aligned</a> <a href="/wiki/Data_structure" title="Data structure">data structure</a> which contains a header, and usable memory. Allocated memory contains an 8- or 16-byte overhead for the size of the chunk and usage flags (similar to a <a href="/wiki/Dope_vector" title="Dope vector">dope vector</a>). Unallocated chunks also store pointers to other free chunks in the usable space area, making the minimum chunk size 16 bytes on 32-bit systems and 24/32 (depends on alignment) bytes on 64-bit systems.<sup id="cite_ref-phrack-57-8_22-1" class="reference"><a href="#cite_note-phrack-57-8-22"><span class="cite-bracket">[</span>22<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-dlmalloc_24-1" class="reference"><a href="#cite_note-dlmalloc-24"><span class="cite-bracket">[</span>24<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Location: 2.8.6, Minimum allocated size">: 2.8.6, Minimum allocated size </span></sup> </p><p>Unallocated memory is grouped into "<a href="/wiki/Bin_(computational_geometry)" title="Bin (computational geometry)">bins</a>" of similar sizes, implemented by using a double-linked list of chunks (with pointers stored in the unallocated space inside the chunk). Bins are sorted by size into three classes:<sup id="cite_ref-phrack-57-8_22-2" class="reference"><a href="#cite_note-phrack-57-8-22"><span class="cite-bracket">[</span>22<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-dlmalloc_24-2" class="reference"><a href="#cite_note-dlmalloc-24"><span class="cite-bracket">[</span>24<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Location: Overlaid data structures">: Overlaid data structures </span></sup> </p> <ul><li>For requests below 256 bytes (a "smallbin" request), a simple two power best fit allocator is used. If there are no free blocks in that bin, a block from the next highest bin is split in two.</li> <li>For requests of 256 bytes or above but below the <a href="/wiki/Mmap" title="Mmap">mmap</a> threshold, dlmalloc since v2.8.0 use <a href="/wiki/Trie#Bitwise_tries" title="Trie">an in-place <i>bitwise trie</i> algorithm</a> ("treebin"). If there is no free space left to satisfy the request, dlmalloc tries to increase the size of the heap, usually via the <a href="/wiki/Sbrk" title="Sbrk">brk</a> system call. This feature was introduced way after ptmalloc was created (from v2.7.x), and as a result is not a part of glibc, which inherits the old best-fit allocator.</li> <li>For requests above the mmap threshold (a "largebin" request), the memory is always allocated using the <a href="/wiki/Mmap" title="Mmap">mmap</a> system call. The threshold is usually 128 KB.<sup id="cite_ref-glibc-env_25-0" class="reference"><a href="#cite_note-glibc-env-25"><span class="cite-bracket">[</span>25<span class="cite-bracket">]</span></a></sup> The mmap method averts problems with huge buffers trapping a small allocation at the end after their expiration, but always allocates an entire <a href="/wiki/Page_(computer_memory)" title="Page (computer memory)">page</a> of memory, which on many architectures is 4096 bytes in size.<sup id="cite_ref-26" class="reference"><a href="#cite_note-26"><span class="cite-bracket">[</span>26<span class="cite-bracket">]</span></a></sup></li></ul> <p>Game developer Adrian Stone argues that <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">dlmalloc</code>, as a boundary-tag allocator, is unfriendly for console systems that have virtual memory but do not have <a href="/wiki/Demand_paging" title="Demand paging">demand paging</a>. This is because its pool-shrinking and growing callbacks (<code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">sysmalloc</code>/<code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">systrim</code>) cannot be used to allocate and commit individual pages of virtual memory. In the absence of demand paging, fragmentation becomes a greater concern.<sup id="cite_ref-27" class="reference"><a href="#cite_note-27"><span class="cite-bracket">[</span>27<span class="cite-bracket">]</span></a></sup> </p><p><span class="anchor" id="jemalloc"></span> </p> <div class="mw-heading mw-heading3"><h3 id="FreeBSD's_and_NetBSD's_jemalloc"><span id="FreeBSD.27s_and_NetBSD.27s_jemalloc"></span>FreeBSD's and NetBSD's jemalloc</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=12" title="Edit section: FreeBSD's and NetBSD's jemalloc"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Since <a href="/wiki/FreeBSD" title="FreeBSD">FreeBSD</a> 7.0 and <a href="/wiki/NetBSD" title="NetBSD">NetBSD</a> 5.0, the old <code>malloc</code> implementation (<code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">phkmalloc</code> by <a href="/wiki/Poul-Henning_Kamp" title="Poul-Henning Kamp">Poul-Henning Kamp</a>) was replaced by <a rel="nofollow" class="external text" href="http://jemalloc.net/">jemalloc</a>, written by Jason Evans. The main reason for this was a lack of scalability of <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">phkmalloc</code> in terms of multithreading. In order to avoid lock contention, <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">jemalloc</code> uses separate "arenas" for each <a href="/wiki/Central_processing_unit" title="Central processing unit">CPU</a>. Experiments measuring number of allocations per second in multithreading application have shown that this makes it scale linearly with the number of threads, while for both phkmalloc and dlmalloc performance was inversely proportional to the number of threads.<sup id="cite_ref-28" class="reference"><a href="#cite_note-28"><span class="cite-bracket">[</span>28<span class="cite-bracket">]</span></a></sup> </p><p><span class="anchor" id="openbsd"></span> </p> <div class="mw-heading mw-heading3"><h3 id="OpenBSD's_malloc"><span id="OpenBSD.27s_malloc"></span>OpenBSD's malloc</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=13" title="Edit section: OpenBSD's malloc"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/OpenBSD" title="OpenBSD">OpenBSD</a>'s implementation of the <code>malloc</code> function makes use of <a href="/wiki/Mmap" title="Mmap">mmap</a>. For requests greater in size than one page, the entire allocation is retrieved using <code>mmap</code>; smaller sizes are assigned from memory pools maintained by <code>malloc</code> within a number of "bucket pages", also allocated with <code>mmap</code>.<sup id="cite_ref-29" class="reference"><a href="#cite_note-29"><span class="cite-bracket">[</span>29<span class="cite-bracket">]</span></a></sup><sup class="noprint Inline-Template noprint noexcerpt Template-Fact" style="white-space:nowrap;">[<i><a href="/wiki/Wikipedia:NOTRS" class="mw-redirect" title="Wikipedia:NOTRS"><span title="This claim needs references to better sources. (November 2015)">better source needed</span></a></i>]</sup> On a call to <code>free</code>, memory is released and unmapped from the process <a href="/wiki/Address_space" title="Address space">address space</a> using <code>munmap</code>. This system is designed to improve security by taking advantage of the <a href="/wiki/Address_space_layout_randomization" title="Address space layout randomization">address space layout randomization</a> and gap page features implemented as part of OpenBSD's <code>mmap</code> <a href="/wiki/System_call" title="System call">system call</a>, and to detect use-after-free bugs—as a large memory allocation is completely unmapped after it is freed, further use causes a <a href="/wiki/Segmentation_fault" title="Segmentation fault">segmentation fault</a> and termination of the program. </p><p>The GrapheneOS project initially started out by porting OpenBSD's memory allocator to Android's Bionic C Library.<sup id="cite_ref-30" class="reference"><a href="#cite_note-30"><span class="cite-bracket">[</span>30<span class="cite-bracket">]</span></a></sup> </p><p><span class="anchor" id="hoard"></span> </p> <div class="mw-heading mw-heading3"><h3 id="Hoard_malloc">Hoard malloc</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=14" title="Edit section: Hoard malloc"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236090951"><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Hoard_memory_allocator" title="Hoard memory allocator">Hoard memory allocator</a></div> <p>Hoard is an allocator whose goal is scalable memory allocation performance. Like OpenBSD's allocator, Hoard uses <code>mmap</code> exclusively, but manages memory in chunks of 64 kilobytes called superblocks. Hoard's heap is logically divided into a single global heap and a number of per-processor heaps. In addition, there is a thread-local cache that can hold a limited number of superblocks. By allocating only from superblocks on the local per-thread or per-processor heap, and moving mostly-empty superblocks to the global heap so they can be reused by other processors, Hoard keeps fragmentation low while achieving near linear scalability with the number of threads.<sup id="cite_ref-31" class="reference"><a href="#cite_note-31"><span class="cite-bracket">[</span>31<span class="cite-bracket">]</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="mimalloc">mimalloc</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=15" title="Edit section: mimalloc"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236090951"><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Mimalloc" title="Mimalloc">mimalloc</a></div> <p>An <a href="/wiki/Open_source" title="Open source">open-source</a> compact general-purpose <a href="/wiki/Memory_allocator" class="mw-redirect" title="Memory allocator">memory allocator</a> from <a href="/wiki/Microsoft_Research" title="Microsoft Research">Microsoft Research</a> with focus on performance.<sup id="cite_ref-32" class="reference"><a href="#cite_note-32"><span class="cite-bracket">[</span>32<span class="cite-bracket">]</span></a></sup> The library is about 11,000 <a href="/wiki/Lines_of_code" class="mw-redirect" title="Lines of code">lines of code</a>. </p><p><span class="anchor" id="tcmalloc"></span> </p> <div class="mw-heading mw-heading3"><h3 id="Thread-caching_malloc_(tcmalloc)"><span id="Thread-caching_malloc_.28tcmalloc.29"></span>Thread-caching malloc (tcmalloc)</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=16" title="Edit section: Thread-caching malloc (tcmalloc)"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Every thread has a <a href="/wiki/Thread-local_storage" title="Thread-local storage">thread-local storage</a> for small allocations. For large allocations mmap or <a href="/wiki/Sbrk" title="Sbrk">sbrk</a> can be used. <a rel="nofollow" class="external text" href="https://code.google.com/p/gperftools/">TCMalloc</a>, a <i>malloc</i> developed by Google,<sup id="cite_ref-33" class="reference"><a href="#cite_note-33"><span class="cite-bracket">[</span>33<span class="cite-bracket">]</span></a></sup> has garbage-collection for local storage of dead threads. The TCMalloc is considered to be more than twice as fast as glibc's ptmalloc for multithreaded programs.<sup id="cite_ref-34" class="reference"><a href="#cite_note-34"><span class="cite-bracket">[</span>34<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-35" class="reference"><a href="#cite_note-35"><span class="cite-bracket">[</span>35<span class="cite-bracket">]</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="In-kernel">In-kernel</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=17" title="Edit section: In-kernel"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Operating system <a href="/wiki/Kernel_(operating_system)" title="Kernel (operating system)">kernels</a> need to allocate memory just as application programs do. The implementation of <code>malloc</code> within a kernel often differs significantly from the implementations used by C libraries, however. For example, memory buffers might need to conform to special restrictions imposed by <a href="/wiki/Direct_memory_access" title="Direct memory access">DMA</a>, or the memory allocation function might be called from interrupt context.<sup id="cite_ref-36" class="reference"><a href="#cite_note-36"><span class="cite-bracket">[</span>36<span class="cite-bracket">]</span></a></sup> This necessitates a <code>malloc</code> implementation tightly integrated with the <a href="/wiki/Virtual_memory" title="Virtual memory">virtual memory</a> subsystem of the operating system kernel. </p> <div class="mw-heading mw-heading2"><h2 id="Overriding_malloc">Overriding malloc</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=18" title="Edit section: Overriding malloc"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Because <code>malloc</code> and its relatives can have a strong impact on the performance of a program, it is not uncommon to override the functions for a specific application by custom implementations that are optimized for application's allocation patterns. The C standard provides no way of doing this, but operating systems have found various ways to do this by exploiting dynamic linking. One way is to simply link in a different library to override the symbols. Another, employed by <a href="/wiki/UNIX_System_V#SVR3" title="UNIX System V">Unix System V.3</a>, is to make <code>malloc</code> and <code>free</code> function pointers that an application can reset to custom functions.<sup id="cite_ref-Levine_1999_CH9_37-0" class="reference"><a href="#cite_note-Levine_1999_CH9-37"><span class="cite-bracket">[</span>37<span class="cite-bracket">]</span></a></sup> </p><p>The most common form on POSIX-like systems is to set the environment variable LD_PRELOAD with the path of the allocator, so that the dynamic linker uses that version of malloc/calloc/free instead of the libc implementation. </p> <div class="mw-heading mw-heading2"><h2 id="Allocation_size_limits">Allocation size limits</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=19" title="Edit section: Allocation size limits"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The largest possible memory block <code>malloc</code> can allocate depends on the host system, particularly the size of physical memory and the operating system implementation. </p><p>Theoretically, the largest number should be the maximum value that can be held in a <code><a href="/wiki/Size_t" class="mw-redirect" title="Size t">size_t</a></code> type, which is an implementation-dependent unsigned integer representing the size of an area of memory. In the <a href="/wiki/C99" title="C99">C99</a> standard and later, it is available as the <code>SIZE_MAX</code> constant from <code><<a href="/wiki/Stdint.h" class="mw-redirect" title="Stdint.h">stdint.h</a>></code>. Although not guaranteed by <span class="nowrap">ISO C</span>, it is usually <code>2^(CHAR_BIT * <a href="/wiki/Sizeof" title="Sizeof">sizeof</a>(size_t)) - 1</code>. </p><p>On glibc systems, the largest possible memory block <code>malloc</code> can allocate is only half this size, namely <code>2^(CHAR_BIT * <a href="/wiki/Sizeof" title="Sizeof">sizeof</a>(ptrdiff_t) - 1) - 1</code>.<sup id="cite_ref-38" class="reference"><a href="#cite_note-38"><span class="cite-bracket">[</span>38<span class="cite-bracket">]</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="Extensions_and_alternatives">Extensions and alternatives</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=20" title="Edit section: Extensions and alternatives"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The C library implementations shipping with various operating systems and compilers may come with alternatives and extensions to the standard <code>malloc</code> interface. Notable among these is: </p> <ul><li><code><a href="/wiki/Alloca" class="mw-redirect" title="Alloca">alloca</a></code>, which allocates a requested number of bytes on the <a href="/wiki/Call_stack" title="Call stack">call stack</a>. No corresponding deallocation function exists, as typically the memory is deallocated as soon as the calling function returns. <code>alloca</code> was present on Unix systems as early as <a href="/wiki/UNIX/32V" title="UNIX/32V">32/V</a> (1978), but its use can be problematic in some (e.g., embedded) contexts.<sup id="cite_ref-39" class="reference"><a href="#cite_note-39"><span class="cite-bracket">[</span>39<span class="cite-bracket">]</span></a></sup> While supported by many compilers, it is not part of the <a href="/wiki/ANSI_C" title="ANSI C">ANSI-C</a> standard and therefore may not always be portable. It may also cause minor performance problems: it leads to variable-size stack frames, so that both <a href="/wiki/Call_stack#STACK-POINTER" title="Call stack">stack and frame pointers</a> need to be managed (with fixed-size stack frames, one of these is redundant).<sup id="cite_ref-40" class="reference"><a href="#cite_note-40"><span class="cite-bracket">[</span>40<span class="cite-bracket">]</span></a></sup> Larger allocations may also increase the risk of undefined behavior due to a <a href="/wiki/Stack_overflow" title="Stack overflow">stack overflow</a>.<sup id="cite_ref-41" class="reference"><a href="#cite_note-41"><span class="cite-bracket">[</span>41<span class="cite-bracket">]</span></a></sup> C99 offered <a href="/wiki/Variable-length_arrays" class="mw-redirect" title="Variable-length arrays">variable-length arrays</a> as an alternative stack allocation mechanism –  however, this feature was relegated to optional in the later <a href="/wiki/C11_(C_standard_revision)" title="C11 (C standard revision)">C11</a> standard.</li> <li><a href="/wiki/POSIX" title="POSIX">POSIX</a> defines a function <code>posix_memalign</code> that allocates memory with caller-specified alignment. Its allocations are deallocated with <code>free</code>,<sup id="cite_ref-42" class="reference"><a href="#cite_note-42"><span class="cite-bracket">[</span>42<span class="cite-bracket">]</span></a></sup> so the implementation usually needs to be a part of the malloc library.</li></ul> <div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=21" title="Edit section: See also"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a href="/wiki/Buffer_overflow" title="Buffer overflow">Buffer overflow</a></li> <li><a href="/wiki/Memory_debugger" title="Memory debugger">Memory debugger</a></li> <li><a href="/wiki/Memory_protection" title="Memory protection">Memory protection</a></li> <li><a href="/wiki/Page_(computer_memory)" title="Page (computer memory)">Page size</a></li> <li><a href="/wiki/Variable-length_array" title="Variable-length array">Variable-length array</a></li></ul> <div class="mw-heading mw-heading2"><h2 id="References">References</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=22" title="Edit section: References"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1239543626">.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}</style><div class="reflist"> <div class="mw-references-wrap mw-references-columns"><ol class="references"> <li id="cite_note-c99-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-c99_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-c99_1-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}</style><cite class="citation techreport cs1"><a rel="nofollow" class="external text" href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf"><i>7.20.3 Memory management functions</i></a> <span class="cs1-format">(PDF)</span>. <i>ISO/IEC 9899:1999 specification</i> (Technical report). p. 313.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=report&rft.btitle=7.20.3+Memory+management+functions&rft.pages=313&rft_id=http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg14%2Fwww%2Fdocs%2Fn1256.pdf&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFSummit" class="citation web cs1">Summit, Steve. <a rel="nofollow" class="external text" href="http://www.eskimo.com/~scs/cclass/notes/sx11.html">"Chapter 11: Memory Allocation"</a>. <i>C Programming Notes</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-07-11</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=C+Programming+Notes&rft.atitle=Chapter+11%3A+Memory+Allocation&rft.aulast=Summit&rft.aufirst=Steve&rft_id=http%3A%2F%2Fwww.eskimo.com%2F~scs%2Fcclass%2Fnotes%2Fsx11.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://linux.die.net/man/3/aligned_alloc">"aligned_alloc(3) - Linux man page"</a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=aligned_alloc%283%29+-+Linux+man+page&rft_id=https%3A%2F%2Flinux.die.net%2Fman%2F3%2Faligned_alloc&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFStroustrup2008" class="citation book cs1"><a href="/wiki/Bjarne_Stroustrup" title="Bjarne Stroustrup">Stroustrup, Bjarne</a> (2008). <i>Programming: Principles and Practice Using C++</i>. Addison Wesley. p. 1009. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <a href="/wiki/Special:BookSources/978-0-321-54372-1" title="Special:BookSources/978-0-321-54372-1"><bdi>978-0-321-54372-1</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=Programming%3A+Principles+and+Practice+Using+C%2B%2B&rft.pages=1009&rft.pub=Addison+Wesley&rft.date=2008&rft.isbn=978-0-321-54372-1&rft.aulast=Stroustrup&rft.aufirst=Bjarne&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html">"gcc manual"</a>. gnu.org<span class="reference-accessdate">. Retrieved <span class="nowrap">2008-12-14</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=gcc+manual&rft.pub=gnu.org&rft_id=https%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc%2FVariable-Length.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text">Brian W. Kernighan, Dennis M. Ritchie, <i>The C Programming Language</i>, Prentice-Hall, 1978; Section 7.9 (page 156) describes <code>calloc</code> and <code>cfree</code>, and Section 8.7 (page 173) describes an implementation for <code>alloc</code> and <code>free</code>.</span> </li> <li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><span class="plainlinksneverexpand"><code><a rel="nofollow" class="external text" href="http://man.cat-v.org/unix-6th/3/alloc">alloc(3)</a></code></span> – <a href="/wiki/Version_6_Unix" title="Version 6 Unix">Version 6 Unix</a> Programmer's <a href="/wiki/Man_page" title="Man page">Manual</a></span> </li> <li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><span class="plainlinksneverexpand"><code><a rel="nofollow" class="external text" href="http://man.cat-v.org/unix_7th/3/malloc">malloc(3)</a></code></span> – <a href="/wiki/Version_7_Unix" title="Version 7 Unix">Version 7 Unix</a> Programmer's <a href="/wiki/Man_page" title="Man page">Manual</a></span> </li> <li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text">Anonymous, <i>Unix Programmer's Manual, Vol. 1</i>, Holt Rinehart and Winston, 1983 (copyright held by Bell Telephone Laboratories, 1983, 1979); The <code>man</code> page for <code>malloc</code> etc. is given on page 275.</span> </li> <li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><span class="plainlinksneverexpand"><code><a rel="nofollow" class="external text" href="https://www.freebsd.org/cgi/man.cgi?query=alloca&sektion=3">alloca(3)</a></code></span> – <a href="/wiki/FreeBSD" title="FreeBSD">FreeBSD</a> Library Functions <a href="/wiki/Man_page" title="Man page">Manual</a></span> </li> <li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text"><span class="plainlinksneverexpand"><code><a rel="nofollow" class="external text" href="https://manned.org/calloc.3">calloc(3)</a></code></span> – <a href="/wiki/Linux" title="Linux">Linux</a> Programmer's <a href="/wiki/Man_page" title="Man page">Manual</a> – Library Functions</span> </li> <li id="cite_note-Cprog_malloc-12"><span class="mw-cite-backlink">^ <a href="#cite_ref-Cprog_malloc_12-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Cprog_malloc_12-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?id=1043284351&answer=1047673478">"Casting malloc"</a>. Cprogramming.com<span class="reference-accessdate">. Retrieved <span class="nowrap">2007-03-09</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=Casting+malloc&rft.pub=Cprogramming.com&rft_id=http%3A%2F%2Ffaq.cprogramming.com%2Fcgi-bin%2Fsmartfaq.cgi%3Fid%3D1043284351%26answer%3D1047673478&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://clang.llvm.org/doxygen/MallocSizeofChecker_8cpp_source.html">"clang: lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp Source File"</a>. <i>clang.llvm.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-04-01</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=clang.llvm.org&rft.atitle=clang%3A+lib%2FStaticAnalyzer%2FCheckers%2FMallocSizeofChecker.cpp+Source+File&rft_id=http%3A%2F%2Fclang.llvm.org%2Fdoxygen%2FMallocSizeofChecker_8cpp_source.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.c-faq.com/malloc/mallocnocast.html">"comp.lang.c FAQ list · Question 7.7b"</a>. C-FAQ<span class="reference-accessdate">. Retrieved <span class="nowrap">2007-03-09</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=comp.lang.c+FAQ+list+%C2%B7+Question+7.7b&rft.pub=C-FAQ&rft_id=http%3A%2F%2Fwww.c-faq.com%2Fmalloc%2Fmallocnocast.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-15">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFReek1997" class="citation book cs1">Reek, Kenneth (1997-08-04). <i>Pointers on C</i> (1 ed.). Pearson. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <a href="/wiki/Special:BookSources/9780673999863" title="Special:BookSources/9780673999863"><bdi>9780673999863</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=Pointers+on+C&rft.edition=1&rft.pub=Pearson&rft.date=1997-08-04&rft.isbn=9780673999863&rft.aulast=Reek&rft.aufirst=Kenneth&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://wiki.sei.cmu.edu/confluence/display/c/MEM04-C.+Beware+of+zero-length+allocations">"MEM04-C. Beware of zero-length allocations - SEI CERT C Coding Standard - Confluence"</a>. <i>wiki.sei.cmu.edu</i>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=wiki.sei.cmu.edu&rft.atitle=MEM04-C.+Beware+of+zero-length+allocations+-+SEI+CERT+C+Coding+Standard+-+Confluence&rft_id=https%3A%2F%2Fwiki.sei.cmu.edu%2Fconfluence%2Fdisplay%2Fc%2FMEM04-C.%2BBeware%2Bof%2Bzero-length%2Ballocations&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-17">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://pubs.opengroup.org/onlinepubs/9699919799/">"POSIX.1-2017: malloc"</a>. <i>pubs.opengroup.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2019-11-29</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=pubs.opengroup.org&rft.atitle=POSIX.1-2017%3A+malloc&rft_id=https%3A%2F%2Fpubs.opengroup.org%2Fonlinepubs%2F9699919799%2F&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFAwakened2019" class="citation web cs1">Awakened (2019-10-02). <a rel="nofollow" class="external text" href="https://awakened1712.github.io/hacking/hacking-whatsapp-gif-rce/">"How a double-free bug in WhatsApp turns to RCE"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2019-11-29</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=How+a+double-free+bug+in+WhatsApp+turns+to+RCE&rft.date=2019-10-02&rft.au=Awakened&rft_id=https%3A%2F%2Fawakened1712.github.io%2Fhacking%2Fhacking-whatsapp-gif-rce%2F&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-19"><span class="mw-cite-backlink"><b><a href="#cite_ref-19">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFFelker2019" class="citation web cs1">Felker, Rich [@RichFelker] (2019-10-03). <a rel="nofollow" class="external text" href="https://x.com/RichFelker/status/1179701167569416192">"Wow. The WhatsApp RCE was the wrong behavior for realloc(p,0) so many implementations insist on"</a> (<a href="/wiki/Tweet_(social_media)" title="Tweet (social media)">Tweet</a>)<span class="reference-accessdate">. Retrieved <span class="nowrap">2022-08-06</span></span> – via <a href="/wiki/Twitter" title="Twitter">Twitter</a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=Wow.+The+WhatsApp+RCE+was+the+wrong+behavior+for+realloc%28p%2C0%29+so+many+implementations+insist+on.&rft.date=2019-10-03&rft.aulast=Felker&rft.aufirst=Rich&rft_id=https%3A%2F%2Fx.com%2FRichFelker%2Fstatus%2F1179701167569416192&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFAlexandrescu2001" class="citation book cs1">Alexandrescu, Andrei (2001). <i>Modern C++ Design: Generic Programming and Design Patterns Applied</i>. Addison-Wesley. p. 78.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=Modern+C%2B%2B+Design%3A+Generic+Programming+and+Design+Patterns+Applied&rft.pages=78&rft.pub=Addison-Wesley&rft.date=2001&rft.aulast=Alexandrescu&rft.aufirst=Andrei&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-21">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://malloc.de/en/">"Wolfram Gloger's malloc homepage"</a>. <i>malloc.de</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-04-01</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=malloc.de&rft.atitle=Wolfram+Gloger%27s+malloc+homepage&rft_id=http%3A%2F%2Fmalloc.de%2Fen%2F&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-phrack-57-8-22"><span class="mw-cite-backlink">^ <a href="#cite_ref-phrack-57-8_22-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-phrack-57-8_22-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-phrack-57-8_22-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFKaempf2001" class="citation journal cs1">Kaempf, Michel (2001). <a rel="nofollow" class="external text" href="http://phrack.org/issues/57/8.html">"Vudo malloc tricks"</a>. <i><a href="/wiki/Phrack" title="Phrack">Phrack</a></i> (57): 8. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20090122071923/http://www.phrack.org/issues.html?issue=57&id=8&mode=txt">Archived</a> from the original on 2009-01-22<span class="reference-accessdate">. Retrieved <span class="nowrap">2009-04-29</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&rft.jtitle=Phrack&rft.atitle=Vudo+malloc+tricks&rft.issue=57&rft.pages=8&rft.date=2001&rft.aulast=Kaempf&rft.aufirst=Michel&rft_id=http%3A%2F%2Fphrack.org%2Fissues%2F57%2F8.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-23"><span class="mw-cite-backlink"><b><a href="#cite_ref-23">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://sourceware.org/glibc/wiki/MallocInternals">"Glibc: Malloc Internals"</a>. <i>sourceware.org Trac</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2019-12-01</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=sourceware.org+Trac&rft.atitle=Glibc%3A+Malloc+Internals&rft_id=https%3A%2F%2Fsourceware.org%2Fglibc%2Fwiki%2FMallocInternals&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-dlmalloc-24"><span class="mw-cite-backlink">^ <a href="#cite_ref-dlmalloc_24-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-dlmalloc_24-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-dlmalloc_24-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFLee" class="citation web cs1">Lee, Doug. <a rel="nofollow" class="external text" href="http://gee.cs.oswego.edu/dl/html/malloc.html">"A Memory Allocator"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2019-12-01</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=A+Memory+Allocator&rft.aulast=Lee&rft.aufirst=Doug&rft_id=http%3A%2F%2Fgee.cs.oswego.edu%2Fdl%2Fhtml%2Fmalloc.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span> <a rel="nofollow" class="external text" href="http://gee.cs.oswego.edu/pub/misc/malloc.c">HTTP for Source Code</a></span> </li> <li id="cite_note-glibc-env-25"><span class="mw-cite-backlink"><b><a href="#cite_ref-glibc-env_25-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.gnu.org/software/libc/manual/html_node/Malloc-Tunable-Parameters.html">"Malloc Tunable Parameters"</a>. <a href="/wiki/GNU" title="GNU">GNU</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2009-05-02</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=Malloc+Tunable+Parameters&rft.pub=GNU&rft_id=https%3A%2F%2Fwww.gnu.org%2Fsoftware%2Flibc%2Fmanual%2Fhtml_node%2FMalloc-Tunable-Parameters.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-26"><span class="mw-cite-backlink"><b><a href="#cite_ref-26">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFSanderson2004" class="citation web cs1">Sanderson, Bruce (2004-12-12). <a rel="nofollow" class="external text" href="http://support.microsoft.com/kb/555223">"RAM, Virtual Memory, Pagefile and all that stuff"</a>. Microsoft Help and Support.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=RAM%2C+Virtual+Memory%2C+Pagefile+and+all+that+stuff&rft.pub=Microsoft+Help+and+Support&rft.date=2004-12-12&rft.aulast=Sanderson&rft.aufirst=Bruce&rft_id=http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F555223&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-27"><span class="mw-cite-backlink"><b><a href="#cite_ref-27">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFStone" class="citation web cs1">Stone, Adrian. <a rel="nofollow" class="external text" href="http://gameangst.com/?p=496">"The Hole That dlmalloc Can't Fill"</a>. <i>Game Angst</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2019-12-01</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=Game+Angst&rft.atitle=The+Hole+That+dlmalloc+Can%27t+Fill&rft.aulast=Stone&rft.aufirst=Adrian&rft_id=http%3A%2F%2Fgameangst.com%2F%3Fp%3D496&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-28"><span class="mw-cite-backlink"><b><a href="#cite_ref-28">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFEvans2006" class="citation web cs1">Evans, Jason (2006-04-16). <a rel="nofollow" class="external text" href="http://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemalloc.pdf">"A Scalable Concurrent malloc(3) Implementation for FreeBSD"</a> <span class="cs1-format">(PDF)</span><span class="reference-accessdate">. Retrieved <span class="nowrap">2012-03-18</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=A+Scalable+Concurrent+malloc%283%29+Implementation+for+FreeBSD&rft.date=2006-04-16&rft.aulast=Evans&rft.aufirst=Jason&rft_id=http%3A%2F%2Fpeople.freebsd.org%2F~jasone%2Fjemalloc%2Fbsdcan2006%2Fjemalloc.pdf&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-29"><span class="mw-cite-backlink"><b><a href="#cite_ref-29">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://bxr.su/OpenBSD/lib/libc/stdlib/malloc.c">"libc/stdlib/malloc.c"</a>. <i>BSD Cross Reference, OpenBSD src/lib/</i>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=BSD+Cross+Reference%2C+OpenBSD+src%2Flib%2F&rft.atitle=libc%2Fstdlib%2Fmalloc.c&rft_id=http%3A%2F%2Fbxr.su%2FOpenBSD%2Flib%2Flibc%2Fstdlib%2Fmalloc.c&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-30"><span class="mw-cite-backlink"><b><a href="#cite_ref-30">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://grapheneos.org/history/">"History | GrapheneOS"</a>. <i>grapheneos.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2023-03-02</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=grapheneos.org&rft.atitle=History+%7C+GrapheneOS&rft_id=https%3A%2F%2Fgrapheneos.org%2Fhistory%2F&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-31"><span class="mw-cite-backlink"><b><a href="#cite_ref-31">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBergerMcKinleyBlumofeWilson2000" class="citation conference cs1">Berger, E. D.; <a href="/wiki/Kathryn_S._McKinley" title="Kathryn S. McKinley">McKinley, K. S.</a>; Blumofe, R. D.; Wilson, P. R. (November 2000). <a rel="nofollow" class="external text" href="http://www.cs.umass.edu/~emery/pubs/berger-asplos2000.pdf"><i>Hoard: A Scalable Memory Allocator for Multithreaded Applications</i></a> <span class="cs1-format">(PDF)</span>. <a href="/wiki/International_Conference_on_Architectural_Support_for_Programming_Languages_and_Operating_Systems" title="International Conference on Architectural Support for Programming Languages and Operating Systems">ASPLOS</a>-IX. <i>Proceedings of the ninth international conference on Architectural support for programming languages and operating systems</i>. pp. 117–128. <a href="/wiki/CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a> <span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1.4174">10.1.1.1.4174</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F378993.379232">10.1145/378993.379232</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <a href="/wiki/Special:BookSources/1-58113-317-0" title="Special:BookSources/1-58113-317-0"><bdi>1-58113-317-0</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=conference&rft.jtitle=Proceedings+of+the+ninth+international+conference+on+Architectural+support+for+programming+languages+and+operating+systems&rft.atitle=Hoard%3A+A+Scalable+Memory+Allocator+for+Multithreaded+Applications&rft.pages=117-128&rft.date=2000-11&rft_id=https%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.1.4174%23id-name%3DCiteSeerX&rft_id=info%3Adoi%2F10.1145%2F378993.379232&rft.isbn=1-58113-317-0&rft.aulast=Berger&rft.aufirst=E.+D.&rft.au=McKinley%2C+K.+S.&rft.au=Blumofe%2C+R.+D.&rft.au=Wilson%2C+P.+R.&rft_id=http%3A%2F%2Fwww.cs.umass.edu%2F~emery%2Fpubs%2Fberger-asplos2000.pdf&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-32"><span class="mw-cite-backlink"><b><a href="#cite_ref-32">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20230614154744/https://slashdot.org/firehose.pl?op=view&id=110928452">"Microsoft releases optimized malloc() as open source - Slashdot"</a>. Archived from <a rel="nofollow" class="external text" href="https://slashdot.org/firehose.pl?op=view&id=110928452">the original</a> on 2023-06-14<span class="reference-accessdate">. Retrieved <span class="nowrap">2020-07-04</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=Microsoft+releases+optimized+malloc%28%29+as+open+source+-+Slashdot&rft_id=https%3A%2F%2Fslashdot.org%2Ffirehose.pl%3Fop%3Dview%26id%3D110928452&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-33"><span class="mw-cite-backlink"><b><a href="#cite_ref-33">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://code.google.com/p/gperftools/">TCMalloc homepage</a></span> </li> <li id="cite_note-34"><span class="mw-cite-backlink"><b><a href="#cite_ref-34">^</a></b></span> <span class="reference-text">Ghemawat, Sanjay; Menage, Paul; <a rel="nofollow" class="external text" href="http://goog-perftools.sourceforge.net/doc/tcmalloc.html"><i>TCMalloc : Thread-Caching Malloc</i></a></span> </li> <li id="cite_note-35"><span class="mw-cite-backlink"><b><a href="#cite_ref-35">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFCallaghan2009" class="citation web cs1">Callaghan, Mark (2009-01-18). <a rel="nofollow" class="external text" href="http://mysqlha.blogspot.com/2009/01/double-sysbench-throughput-with_18.html">"High Availability MySQL: Double sysbench throughput with TCMalloc"</a>. <i>Mysqlha.blogspot.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2011-09-18</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=Mysqlha.blogspot.com&rft.atitle=High+Availability+MySQL%3A+Double+sysbench+throughput+with+TCMalloc&rft.date=2009-01-18&rft.aulast=Callaghan&rft.aufirst=Mark&rft_id=http%3A%2F%2Fmysqlha.blogspot.com%2F2009%2F01%2Fdouble-sysbench-throughput-with_18.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-36"><span class="mw-cite-backlink"><b><a href="#cite_ref-36">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://people.netfilter.org/rusty/unreliable-guides/kernel-hacking/routines-kmalloc.html">"kmalloc()/kfree() include/linux/slab.h"</a>. <i>People.netfilter.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2011-09-18</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=People.netfilter.org&rft.atitle=kmalloc%28%29%2Fkfree%28%29+include%2Flinux%2Fslab.h&rft_id=http%3A%2F%2Fpeople.netfilter.org%2Frusty%2Funreliable-guides%2Fkernel-hacking%2Froutines-kmalloc.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-Levine_1999_CH9-37"><span class="mw-cite-backlink"><b><a href="#cite_ref-Levine_1999_CH9_37-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFLevine2000" class="citation book cs1"><a href="/wiki/John_R._Levine" title="John R. Levine">Levine, John R.</a> (2000) [October 1999]. <a rel="nofollow" class="external text" href="https://archive.today/20130126001629/http://www.iecc.com/linker/linker09.html">"Chapter 9: Shared libraries"</a>. <a rel="nofollow" class="external text" href="https://www.iecc.com/linker/"><i>Linkers and Loaders</i></a>. The Morgan Kaufmann Series in Software Engineering and Programming (1 ed.). San Francisco, USA: <a href="/wiki/Morgan_Kaufmann" class="mw-redirect" title="Morgan Kaufmann">Morgan Kaufmann</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <a href="/wiki/Special:BookSources/1-55860-496-0" title="Special:BookSources/1-55860-496-0"><bdi>1-55860-496-0</bdi></a>. <a href="/wiki/OCLC_(identifier)" class="mw-redirect" title="OCLC (identifier)">OCLC</a> <a rel="nofollow" class="external text" href="https://search.worldcat.org/oclc/42413382">42413382</a>. <a rel="nofollow" class="external text" href="https://archive.today/20121205032107/http://www.iecc.com/linker/">Archived</a> from the original on 2012-12-05<span class="reference-accessdate">. Retrieved <span class="nowrap">2020-01-12</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=bookitem&rft.atitle=Chapter+9%3A+Shared+libraries&rft.btitle=Linkers+and+Loaders&rft.place=San+Francisco%2C+USA&rft.series=The+Morgan+Kaufmann+Series+in+Software+Engineering+and+Programming&rft.edition=1&rft.pub=Morgan+Kaufmann&rft.date=2000&rft_id=info%3Aoclcnum%2F42413382&rft.isbn=1-55860-496-0&rft.aulast=Levine&rft.aufirst=John+R.&rft_id=https%3A%2F%2Farchive.today%2F20130126001629%2Fhttp%3A%2F%2Fwww.iecc.com%2Flinker%2Flinker09.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span> Code: <a rel="nofollow" class="external autonumber" href="https://archive.today/20200114225034/https://linker.iecc.com/code.html">[1]</a><a rel="nofollow" class="external autonumber" href="ftp://ftp.iecc.com/pub/linker/">[2]</a> Errata: <a rel="nofollow" class="external autonumber" href="https://linker.iecc.com/">[3]</a></span> </li> <li id="cite_note-38"><span class="mw-cite-backlink"><b><a href="#cite_ref-38">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://sourceware.org/bugzilla/show_bug.cgi?id=23741#c2">"malloc: make malloc fail with requests larger than PTRDIFF_MAX"</a>. <i>Sourceware Bugzilla</i>. 2019-04-18<span class="reference-accessdate">. Retrieved <span class="nowrap">2020-07-30</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=Sourceware+Bugzilla&rft.atitle=malloc%3A+make+malloc+fail+with+requests+larger+than+PTRDIFF_MAX&rft.date=2019-04-18&rft_id=https%3A%2F%2Fsourceware.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D23741%23c2&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-39"><span class="mw-cite-backlink"><b><a href="#cite_ref-39">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://stackoverflow.com/questions/1018853/why-is-the-use-of-alloca-not-considered-good-practice">"Why is the use of alloca() not considered good practice?"</a>. <i>stackoverflow.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2016-01-05</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=stackoverflow.com&rft.atitle=Why+is+the+use+of+alloca%28%29+not+considered+good+practice%3F&rft_id=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1018853%2Fwhy-is-the-use-of-alloca-not-considered-good-practice&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-40"><span class="mw-cite-backlink"><b><a href="#cite_ref-40">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFAmarasingheLeiserson2010" class="citation web cs1">Amarasinghe, Saman; Leiserson, Charles (2010). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20150622092347/http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-172-performance-engineering-of-software-systems-fall-2010/video-lectures/lecture-8-cache-efficient-algorithms/">"6.172 Performance Engineering of Software Systems, Lecture 10"</a>. <i>MIT OpenCourseWare</i>. Massachusetts Institute of Technology. Archived from <a rel="nofollow" class="external text" href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-172-performance-engineering-of-software-systems-fall-2010/video-lectures/lecture-8-cache-efficient-algorithms/">the original</a> on 2015-06-22<span class="reference-accessdate">. Retrieved <span class="nowrap">2015-01-27</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=MIT+OpenCourseWare&rft.atitle=6.172+Performance+Engineering+of+Software+Systems%2C+Lecture+10&rft.date=2010&rft.aulast=Amarasinghe&rft.aufirst=Saman&rft.au=Leiserson%2C+Charles&rft_id=http%3A%2F%2Focw.mit.edu%2Fcourses%2Felectrical-engineering-and-computer-science%2F6-172-performance-engineering-of-software-systems-fall-2010%2Fvideo-lectures%2Flecture-8-cache-efficient-algorithms%2F&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-41"><span class="mw-cite-backlink"><b><a href="#cite_ref-41">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://man7.org/linux/man-pages/man3/alloca.3.html">"alloca(3) - Linux manual page"</a>. <i>man7.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2016-01-05</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=man7.org&rft.atitle=alloca%283%29+-+Linux+manual+page&rft_id=http%3A%2F%2Fman7.org%2Flinux%2Fman-pages%2Fman3%2Falloca.3.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3AC+dynamic+memory+allocation" class="Z3988"></span></span> </li> <li id="cite_note-42"><span class="mw-cite-backlink"><b><a href="#cite_ref-42">^</a></b></span> <span class="reference-text"><span class="plainlinksneverexpand"><code><a rel="nofollow" class="external text" href="https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_memalign.html">posix_memalign</a></code></span> – System Interfaces Reference, <a href="/wiki/Single_Unix_Specification" class="mw-redirect" title="Single Unix Specification">The Single UNIX Specification</a>, Version 4 from <a href="/wiki/The_Open_Group" title="The Open Group">The Open Group</a></span> </li> </ol></div></div> <div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=C_dynamic_memory_allocation&action=edit&section=23" title="Edit section: External links"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1235681985">.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}</style><style data-mw-deduplicate="TemplateStyles:r1237033735">@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}</style><div class="side-box side-box-right plainlinks sistersitebox"><style data-mw-deduplicate="TemplateStyles:r1126788409">.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}</style> <div class="side-box-flex"> <div class="side-box-image"><span class="noviewer" typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.png" decoding="async" width="40" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/60px-Wikibooks-logo-en-noslogan.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/80px-Wikibooks-logo-en-noslogan.svg.png 2x" data-file-width="400" data-file-height="400" /></span></span></div> <div class="side-box-text plainlist">The Wikibook <i><a href="https://en.wikibooks.org/wiki/C_Programming" class="extiw" title="wikibooks:C Programming">C Programming</a></i> has a page on the topic of: <i><b><a href="https://en.wikibooks.org/wiki/C_Programming/C_dynamic_memory_management" class="extiw" title="wikibooks:C Programming/C dynamic memory management">C Programming/C Reference</a></b></i></div></div> </div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1235681985"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1237033735"><div class="side-box side-box-right plainlinks sistersitebox"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1126788409"> <div class="side-box-flex"> <div class="side-box-image"><span class="noviewer" typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Wikiversity_logo_2017.svg/40px-Wikiversity_logo_2017.svg.png" decoding="async" width="40" height="33" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Wikiversity_logo_2017.svg/60px-Wikiversity_logo_2017.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Wikiversity_logo_2017.svg/80px-Wikiversity_logo_2017.svg.png 2x" data-file-width="626" data-file-height="512" /></span></span></div> <div class="side-box-text plainlist">Wikiversity has learning resources about <i><b><a href="https://en.wikiversity.org/wiki/C/Memory_Management" class="extiw" title="v:C/Memory Management">C/Memory_Management</a></b></i></div></div> </div> <ul><li><a rel="nofollow" class="external text" href="http://www.opengroup.org/onlinepubs/9699919799/functions/malloc.html">Definition of malloc in IEEE Std 1003.1 standard</a></li> <li><a href="/wiki/Doug_Lea" title="Doug Lea">Lea, Doug</a>; <a rel="nofollow" class="external text" href="http://gee.cs.oswego.edu/dl/html/malloc.html"><i>The design of the basis of the glibc allocator</i></a></li> <li>Gloger, Wolfram; <a rel="nofollow" class="external text" href="http://www.malloc.de/en/"><i>The ptmalloc homepage</i></a></li> <li>Berger, Emery; <a rel="nofollow" class="external text" href="http://www.hoard.org/"><i>The Hoard homepage</i></a></li> <li>Douglas, Niall; <a rel="nofollow" class="external text" href="http://www.nedprod.com/programs/portable/nedmalloc/"><i>The nedmalloc homepage</i></a></li> <li>Evans, Jason; <a rel="nofollow" class="external text" href="http://jemalloc.net/"><i>The jemalloc homepage</i></a></li> <li>Google; <a rel="nofollow" class="external text" href="https://github.com/gperftools/gperftools/wiki"><i>The tcmalloc homepage</i></a></li> <li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20060409094110/http://www.osdcom.info/content/view/31/39/"><i>Simple Memory Allocation Algorithms</i></a> on OSDEV Community</li> <li>Michael, Maged M.; <a rel="nofollow" class="external text" href="http://www.research.ibm.com/people/m/michael/pldi-2004.pdf"><i>Scalable Lock-Free Dynamic Memory Allocation</i></a></li> <li>Bartlett, Jonathan; <a rel="nofollow" class="external text" href="http://www.ibm.com/developerworks/library/l-memory/"><i>Inside memory management</i> – The choices, tradeoffs, and implementations of dynamic allocation</a></li> <li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20050823083743/http://live.gnome.org/MemoryReduction">Memory Reduction (GNOME)</a> wiki page with much information about fixing malloc</li> <li><a rel="nofollow" class="external text" href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf">C99 standard draft, including TC1/TC2/TC3</a></li> <li><a rel="nofollow" class="external text" href="http://paste.tclers.tk/1596">Some useful references about C</a></li> <li><a rel="nofollow" class="external text" href="http://www.open-std.org/jtc1/sc22/wg14/www/standards">ISO/IEC 9899 – Programming languages – C</a></li> <li><a rel="nofollow" class="external text" href="https://sploitfun.wordpress.com/2015/02/10/understanding-glibc-malloc/"><i>Understanding glibc malloc</i></a></li></ul> <div class="navbox-styles"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><style data-mw-deduplicate="TemplateStyles:r1236075235">.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}</style></div><div role="navigation" class="navbox" aria-labelledby="Memory_management" style="padding:3px"><table class="nowraplinks hlist mw-collapsible expanded navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1239400231"><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:Memory_management" title="Template:Memory management"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:Memory_management" title="Template talk:Memory management"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:Memory_management" title="Special:EditPage/Template:Memory management"><abbr title="Edit this template">e</abbr></a></li></ul></div><div id="Memory_management" style="font-size:114%;margin:0 4em"><a href="/wiki/Memory_management" title="Memory management">Memory management</a></div></th></tr><tr><td class="navbox-abovebelow" colspan="2"><div> <ul><li><a href="/wiki/Memory_management_(operating_systems)" title="Memory management (operating systems)">Memory management as a function of an operating system</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Hardware</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Memory_management_unit" title="Memory management unit">Memory management unit</a> (MMU)</li> <li><a href="/wiki/Translation_lookaside_buffer" title="Translation lookaside buffer">Translation lookaside buffer</a> (TLB)</li> <li><a href="/wiki/Input%E2%80%93output_memory_management_unit" title="Input–output memory management unit">Input–output memory management unit</a> (IOMMU)</li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Virtual_memory" title="Virtual memory">Virtual memory</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Demand_paging" title="Demand paging">Demand paging</a></li> <li><a href="/wiki/Memory_paging" title="Memory paging">Memory paging</a></li> <li><a href="/wiki/Page_table" title="Page table">Page table</a></li> <li><a href="/wiki/Virtual_memory_compression" title="Virtual memory compression">Virtual memory compression</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Memory_segmentation" title="Memory segmentation">Memory segmentation</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Protected_mode" title="Protected mode">Protected mode</a></li> <li><a href="/wiki/Real_mode" title="Real mode">Real mode</a></li> <li><a href="/wiki/Virtual_8086_mode" title="Virtual 8086 mode">Virtual 8086 mode</a></li> <li><a href="/wiki/X86_memory_segmentation" title="X86 memory segmentation">x86 memory segmentation</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Memory_allocator" class="mw-redirect" title="Memory allocator">Memory allocator</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Dlmalloc" class="mw-redirect" title="Dlmalloc">dlmalloc</a></li> <li><a href="/wiki/Hoard_memory_allocator" title="Hoard memory allocator">Hoard</a></li> <li><a href="/wiki/Jemalloc" class="mw-redirect" title="Jemalloc">jemalloc</a></li> <li><a href="/wiki/Libumem" title="Libumem">libumem</a></li> <li><a href="/wiki/Mimalloc" title="Mimalloc">mimalloc</a></li> <li><a href="/wiki/Ptmalloc" class="mw-redirect" title="Ptmalloc">ptmalloc</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Manual_memory_management" title="Manual memory management">Manual memory management</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Static_variable" title="Static variable">Static memory allocation</a></li> <li><a class="mw-selflink selflink">C dynamic memory allocation</a></li> <li><a href="/wiki/New_and_delete_(C%2B%2B)" title="New and delete (C++)">new and delete (C++)</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">Garbage collection</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Automatic_Reference_Counting" title="Automatic Reference Counting">Automatic Reference Counting</a></li> <li><a href="/wiki/Boehm_garbage_collector" title="Boehm garbage collector">Boehm garbage collector</a></li> <li><a href="/wiki/Cheney%27s_algorithm" title="Cheney's algorithm">Cheney's algorithm</a></li> <li><a href="/wiki/Concurrent_mark_sweep_collector" title="Concurrent mark sweep collector">Concurrent mark sweep collector</a></li> <li><a href="/wiki/Finalizer" title="Finalizer">Finalizer</a></li> <li><a href="/wiki/Garbage_(computer_science)" title="Garbage (computer science)">Garbage</a></li> <li><a href="/wiki/Garbage-first_collector" title="Garbage-first collector">Garbage-first collector</a></li> <li><a href="/wiki/Mark%E2%80%93compact_algorithm" title="Mark–compact algorithm">Mark–compact algorithm</a></li> <li><a href="/wiki/Reference_counting" title="Reference counting">Reference counting</a></li> <li><a href="/wiki/Tracing_garbage_collection" title="Tracing garbage collection">Tracing garbage collection</a></li> <li><a href="/wiki/Weak_reference" title="Weak reference">Strong reference</a></li> <li><a href="/wiki/Weak_reference" title="Weak reference">Weak reference</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Memory_safety" title="Memory safety">Memory safety</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Buffer_overflow" title="Buffer overflow">Buffer overflow</a></li> <li><a href="/wiki/Buffer_over-read" title="Buffer over-read">Buffer over-read</a></li> <li><a href="/wiki/Dangling_pointer" title="Dangling pointer">Dangling pointer</a></li> <li><a href="/wiki/Stack_overflow" title="Stack overflow">Stack overflow</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Issues</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Fragmentation_(computing)" title="Fragmentation (computing)">Fragmentation</a></li> <li><a href="/wiki/Memory_leak" title="Memory leak">Memory leak</a></li> <li><a href="/wiki/Unreachable_memory" title="Unreachable memory">Unreachable memory</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Other</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Automatic_variable" title="Automatic variable">Automatic variable</a></li> <li><a href="/wiki/International_Symposium_on_Memory_Management" title="International Symposium on Memory Management">International Symposium on Memory Management</a></li> <li><a href="/wiki/Region-based_memory_management" title="Region-based memory management">Region-based memory management</a></li> <li><a href="/wiki/Memory_pool" title="Memory pool">Memory pool</a></li></ul> </div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div> <ul><li><span class="noviewer" typeof="mw:File"><span title="Category"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/16px-Symbol_category_class.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/23px-Symbol_category_class.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/31px-Symbol_category_class.svg.png 2x" data-file-width="180" data-file-height="185" /></span></span> <a href="/wiki/Category:Memory_management" title="Category:Memory management">Memory management</a></li> <li><span class="noviewer" typeof="mw:File"><span title="Category"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/16px-Symbol_category_class.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/23px-Symbol_category_class.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/31px-Symbol_category_class.svg.png 2x" data-file-width="180" data-file-height="185" /></span></span> <a href="/wiki/Category:Virtual_memory" title="Category:Virtual memory">Virtual memory</a></li> <li><span class="noviewer" typeof="mw:File"><span title="Category"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/16px-Symbol_category_class.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/23px-Symbol_category_class.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/31px-Symbol_category_class.svg.png 2x" data-file-width="180" data-file-height="185" /></span></span> <a href="/wiki/Category:Automatic_memory_management" title="Category:Automatic memory management">Automatic memory management</a></li> <li><span class="noviewer" typeof="mw:File"><span title="Category"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/16px-Symbol_category_class.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/23px-Symbol_category_class.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/31px-Symbol_category_class.svg.png 2x" data-file-width="180" data-file-height="185" /></span></span> <a href="/wiki/Category:Memory_management_algorithms" title="Category:Memory management algorithms">Memory management algorithms</a></li> <li><span class="noviewer" typeof="mw:File"><span title="Category"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/16px-Symbol_category_class.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/23px-Symbol_category_class.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/31px-Symbol_category_class.svg.png 2x" data-file-width="180" data-file-height="185" /></span></span> <a href="/wiki/Category:Memory_management_software" title="Category:Memory management software">Memory management software</a></li></ul> </div></td></tr></tbody></table></div> <div class="navbox-styles"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236075235"></div><div role="navigation" class="navbox" aria-labelledby="C_programming_language" style="padding:3px"><table class="nowraplinks hlist mw-collapsible expanded navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1239400231"><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:C_programming_language" title="Template:C programming language"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:C_programming_language" title="Template talk:C programming language"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:C_programming_language" title="Special:EditPage/Template:C programming language"><abbr title="Edit this template">e</abbr></a></li></ul></div><div id="C_programming_language" style="font-size:114%;margin:0 4em"><a href="/wiki/C_(programming_language)" title="C (programming language)">C programming language</a></div></th></tr><tr><td class="navbox-abovebelow" colspan="2"><div> <ul><li><a href="/wiki/ANSI_C" title="ANSI C">ANSI C</a></li> <li><a href="/wiki/C99" title="C99">C99</a></li> <li><a href="/wiki/C11_(C_standard_revision)" title="C11 (C standard revision)">C11</a></li> <li><a href="/wiki/C17_(C_standard_revision)" title="C17 (C standard revision)">C17</a></li> <li><a href="/wiki/C23_(C_standard_revision)" title="C23 (C standard revision)">C23</a></li> <li><a href="/wiki/Embedded_C" title="Embedded C">Embedded C</a></li> <li><a href="/wiki/MISRA_C" title="MISRA C">MISRA C</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Features</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Subroutine" class="mw-redirect" title="Subroutine">Functions</a></li> <li><a href="/wiki/Include_directive#C" title="Include directive">Header files</a></li> <li><a href="/wiki/Operators_in_C_and_C%2B%2B" title="Operators in C and C++">Operators</a></li> <li><a href="/wiki/C_string_handling" title="C string handling">String</a></li> <li><a href="/wiki/C_syntax" title="C syntax">Syntax</a></li> <li><a href="/wiki/C_preprocessor" title="C preprocessor">Preprocessor</a></li> <li><a href="/wiki/C_data_types" title="C data types">Data types</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/C_standard_library" title="C standard library">Standard library</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><td colspan="2" class="navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/C_character_classification" title="C character classification">Char</a></li> <li><a href="/wiki/C_file_input/output" title="C file input/output">File I/O</a></li> <li><a href="/wiki/C_mathematical_functions" title="C mathematical functions">Math</a></li> <li><a class="mw-selflink selflink">Dynamic memory</a></li> <li><a href="/wiki/C_string_handling" title="C string handling">String</a></li> <li><a href="/wiki/C_date_and_time_functions" title="C date and time functions">Time</a></li> <li><a href="/wiki/Stdarg.h" title="Stdarg.h">Variadic</a></li> <li><a href="/wiki/C_POSIX_library" title="C POSIX library">POSIX</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Implementations</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Bionic_(software)" title="Bionic (software)">Bionic</a> <ul><li><a href="/wiki/Hybris_(software)" class="mw-redirect" title="Hybris (software)">libhybris</a></li></ul></li> <li><a href="/wiki/Dietlibc" title="Dietlibc">dietlibc</a></li> <li><a href="/wiki/Glibc" title="Glibc">glibc</a> <ul><li><a href="/wiki/Embedded_GLIBC" class="mw-redirect" title="Embedded GLIBC">EGLIBC</a></li></ul></li> <li><a href="/wiki/Klibc" title="Klibc">klibc</a></li> <li><a href="/wiki/Microsoft_Windows_library_files" title="Microsoft Windows library files">Windows CRT</a></li> <li><a href="/wiki/Musl" title="Musl">musl</a></li> <li><a href="/wiki/Newlib" title="Newlib">Newlib</a></li> <li><a href="/wiki/UClibc" title="UClibc">uClibc</a></li></ul> </div></td></tr></tbody></table><div></div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/List_of_C_compilers" class="mw-redirect" title="List of C compilers">Compilers</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Amsterdam_Compiler_Kit" title="Amsterdam Compiler Kit">ACK</a></li> <li><a href="/wiki/Borland_Turbo_C" class="mw-redirect" title="Borland Turbo C">Borland Turbo C</a></li> <li><a href="/wiki/Clang" title="Clang">Clang</a></li> <li><a href="/wiki/GNU_Compiler_Collection" title="GNU Compiler Collection">GCC</a></li> <li><a href="/wiki/Intel_C%2B%2B_Compiler" title="Intel C++ Compiler">ICC</a></li> <li><a href="/wiki/LCC_(compiler)" title="LCC (compiler)">LCC</a></li> <li><a href="/wiki/Norcroft_C_compiler" title="Norcroft C compiler">Norcroft C</a></li> <li><a href="/wiki/Portable_C_Compiler" title="Portable C Compiler">PCC</a></li> <li><a href="/wiki/Small_Device_C_Compiler" title="Small Device C Compiler">SDCC</a></li> <li><a href="/wiki/Tiny_C_Compiler" title="Tiny C Compiler">TCC</a></li> <li><a href="/wiki/Visual_Studio" title="Visual Studio">Visual Studio</a>, <a href="/wiki/Microsoft_Visual_Studio_Express" title="Microsoft Visual Studio Express">Express</a>, <a href="/wiki/Microsoft_Visual_C%2B%2B" title="Microsoft Visual C++">C++</a></li> <li><a href="/wiki/Watcom_C/C%2B%2B" title="Watcom C/C++">Watcom C/C++</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Integrated_development_environment" title="Integrated development environment">IDEs</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Anjuta" title="Anjuta">Anjuta</a></li> <li><a href="/wiki/CLion" class="mw-redirect" title="CLion">CLion</a></li> <li><a href="/wiki/Code::Blocks" title="Code::Blocks">Code::Blocks</a></li> <li><a href="/wiki/CodeLite" title="CodeLite">CodeLite</a></li> <li><a href="/wiki/Eclipse_(software)" title="Eclipse (software)">Eclipse</a></li> <li><a href="/wiki/Geany" title="Geany">Geany</a></li> <li><a href="/wiki/GNOME_Builder" title="GNOME Builder">GNOME Builder</a></li> <li><a href="/wiki/KDevelop" title="KDevelop">KDevelop</a></li> <li><a href="/wiki/Visual_Studio" title="Visual Studio">Visual Studio</a></li> <li><a href="/wiki/NetBeans" title="NetBeans">NetBeans</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Comparison with<br />other languages</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Compatibility_of_C_and_C%2B%2B" title="Compatibility of C and C++">Compatibility of C and C++</a></li> <li><a href="/wiki/Comparison_of_Pascal_and_C" title="Comparison of Pascal and C">Comparison with Pascal</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Descendant<br />languages</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/C%2B%2B" title="C++">C++</a></li> <li><a href="/wiki/C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a></li> <li><a href="/wiki/D_(programming_language)" title="D (programming language)">D</a></li> <li><a href="/wiki/Objective-C" title="Objective-C">Objective-C</a></li> <li><a href="/wiki/Alef_(programming_language)" title="Alef (programming language)">Alef</a></li> <li><a href="/wiki/Limbo_(programming_language)" title="Limbo (programming language)">Limbo</a></li> <li><a href="/wiki/Go_(programming_language)" title="Go (programming language)">Go</a></li> <li><a href="/wiki/Vala_(programming_language)" title="Vala (programming language)">Vala</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Designer</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Dennis_Ritchie" title="Dennis Ritchie">Dennis Ritchie</a></li></ul> </div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div> <ul><li><span class="noviewer" typeof="mw:File"><span title="Category"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/16px-Symbol_category_class.svg.png" decoding="async" width="16" height="16" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/23px-Symbol_category_class.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/96/Symbol_category_class.svg/31px-Symbol_category_class.svg.png 2x" data-file-width="180" data-file-height="185" /></span></span> <b><a href="/wiki/Category:C_(programming_language)" title="Category:C (programming language)">Category</a></b></li></ul> </div></td></tr></tbody></table></div> <!-- NewPP limit report Parsed by mw‐web.codfw.main‐f69cdc8f6‐5blz9 Cached time: 20241122141144 Cache expiry: 2592000 Reduced expiry: false Complications: [vary‐revision‐sha1, show‐toc] CPU time usage: 0.772 seconds Real time usage: 1.071 seconds Preprocessor visited node count: 4620/1000000 Post‐expand include size: 113820/2097152 bytes Template argument size: 6196/2097152 bytes Highest expansion depth: 16/100 Expensive parser function count: 32/500 Unstrip recursion depth: 1/20 Unstrip post‐expand size: 158413/5000000 bytes Lua time usage: 0.434/10.000 seconds Lua memory usage: 7679929/52428800 bytes Number of Wikibase entities loaded: 0/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 898.513 1 -total 36.83% 330.914 1 Template:Reflist 13.77% 123.765 25 Template:Cite_web 11.35% 101.963 1 Template:C_Standard_Library 10.66% 95.813 1 Template:Sidebar 9.59% 86.186 1 Template:Short_description 9.01% 80.973 1 Template:Cite_tech_report 6.50% 58.394 1 Template:Redirect 6.38% 57.292 3 Template:Navbox 6.24% 56.067 1 Template:Memory_management_navbox --> <!-- Saved in parser cache with key enwiki:pcache:384289:|#|:idhash:canonical and timestamp 20241122141144 and revision id 1258413351. Rendering was triggered because: page-view --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://en.wikipedia.org/w/index.php?title=C_dynamic_memory_allocation&oldid=1258413351">https://en.wikipedia.org/w/index.php?title=C_dynamic_memory_allocation&oldid=1258413351</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Help:Category" title="Help:Category">Categories</a>: <ul><li><a href="/wiki/Category:Memory_management" title="Category:Memory management">Memory management</a></li><li><a href="/wiki/Category:Memory_management_software" title="Category:Memory management software">Memory management software</a></li><li><a href="/wiki/Category:C_standard_library" title="Category:C standard library">C standard library</a></li><li><a href="/wiki/Category:C%2B%2B" title="Category:C++">C++</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Hidden categories: <ul><li><a href="/wiki/Category:Articles_with_short_description" title="Category:Articles with short description">Articles with short description</a></li><li><a href="/wiki/Category:Short_description_is_different_from_Wikidata" title="Category:Short description is different from Wikidata">Short description is different from Wikidata</a></li><li><a href="/wiki/Category:Use_dmy_dates_from_May_2021" title="Category:Use dmy dates from May 2021">Use dmy dates from May 2021</a></li><li><a href="/wiki/Category:All_articles_with_unsourced_statements" title="Category:All articles with unsourced statements">All articles with unsourced statements</a></li><li><a href="/wiki/Category:Articles_with_unsourced_statements_from_July_2022" title="Category:Articles with unsourced statements from July 2022">Articles with unsourced statements from July 2022</a></li><li><a href="/wiki/Category:Articles_with_example_C%2B%2B_code" title="Category:Articles with example C++ code">Articles with example C++ code</a></li><li><a href="/wiki/Category:All_articles_lacking_reliable_references" title="Category:All articles lacking reliable references">All articles lacking reliable references</a></li><li><a href="/wiki/Category:Articles_lacking_reliable_references_from_November_2015" title="Category:Articles lacking reliable references from November 2015">Articles lacking reliable references from November 2015</a></li><li><a href="/wiki/Category:Articles_with_example_C_code" title="Category:Articles with example C code">Articles with example C code</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 19 November 2024, at 16:03<span class="anonymous-show"> (UTC)</span>.</li> <li id="footer-info-copyright">Text is available under the <a href="/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License" title="Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use" class="extiw" title="foundation:Special:MyLanguage/Policy:Terms of Use">Terms of Use</a> and <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy" class="extiw" title="foundation:Special:MyLanguage/Policy:Privacy policy">Privacy Policy</a>. Wikipedia® is a registered trademark of the <a rel="nofollow" class="external text" href="https://wikimediafoundation.org/">Wikimedia Foundation, Inc.</a>, a non-profit organization.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Wikipedia:About">About Wikipedia</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Wikipedia:General_disclaimer">Disclaimers</a></li> <li id="footer-places-contact"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us">Contact Wikipedia</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=C_dynamic_memory_allocation&mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-5cd4cd96d5-kvt4l","wgBackendResponseTime":155,"wgPageParseReport":{"limitreport":{"cputime":"0.772","walltime":"1.071","ppvisitednodes":{"value":4620,"limit":1000000},"postexpandincludesize":{"value":113820,"limit":2097152},"templateargumentsize":{"value":6196,"limit":2097152},"expansiondepth":{"value":16,"limit":100},"expensivefunctioncount":{"value":32,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":158413,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 898.513 1 -total"," 36.83% 330.914 1 Template:Reflist"," 13.77% 123.765 25 Template:Cite_web"," 11.35% 101.963 1 Template:C_Standard_Library"," 10.66% 95.813 1 Template:Sidebar"," 9.59% 86.186 1 Template:Short_description"," 9.01% 80.973 1 Template:Cite_tech_report"," 6.50% 58.394 1 Template:Redirect"," 6.38% 57.292 3 Template:Navbox"," 6.24% 56.067 1 Template:Memory_management_navbox"]},"scribunto":{"limitreport-timeusage":{"value":"0.434","limit":"10.000"},"limitreport-memusage":{"value":7679929,"limit":52428800}},"cachereport":{"origin":"mw-web.codfw.main-f69cdc8f6-5blz9","timestamp":"20241122141144","ttl":2592000,"transientcontent":false}}});});</script> <script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"C dynamic memory allocation","url":"https:\/\/en.wikipedia.org\/wiki\/C_dynamic_memory_allocation","sameAs":"http:\/\/www.wikidata.org\/entity\/Q1050390","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q1050390","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2003-12-01T09:01:58Z","dateModified":"2024-11-19T16:03:00Z","headline":"memory management"}</script> </body> </html>