Data segment

In computing, a data segment (often denoted .data) is a portion of an object file or the corresponding address space of a program that contains initialized static variables, that is, global variables and static local variables. The size of this segment is determined by the size of the values in the program's source code, and does not change at run time.

The data segment is read/write, since the values of variables can be altered at run time. This is in contrast to the read-only data segment (rodata segment or .rodata), which contains static constants rather than variables; it also contrasts to the code segment, also known as the text segment, which is read-only on many architectures. Uninitialized data, both variables and constants, is instead in the BSS segment.

Historically, to be able to support memory address spaces larger than the native size of the internal address register would allow, early CPUs implemented a system of segmentation whereby they would store a small set of indexes to use as offsets to certain areas. The Intel 8086 family of CPUs provided four segments: the code segment, the data segment, the stack segment and the extra segment. Each segment was placed at a specific location in memory by the software being executed and all instructions that operated on the data within those segments were performed relative to the start of that segment. This allowed a 16-bit address register, which would normally be able to access 64 KB of memory space, to access 1 MB of memory space.

This segmenting of the memory space into discrete blocks with specific tasks carried over into the programming languages of the day and the concept is still widely in use within modern programming languages.

Program memory

A computer program memory can be largely categorized into two sections: read-only and read/write. This distinction grew from early systems holding their main program in read-only memory such as Mask ROM, EPROM, PROM or EEPROM. As systems became more complex and programs were loaded from other media into RAM instead of executing from ROM, the idea that some portions of the program's memory should not be modified was retained. These became the .text and .rodata segments of the program, and the remainder which could be written to divided into a number of other segments for specific tasks.

Code

The code segment, also known as text segment, contains executable code and is generally read-only and fixed size.

Data

This shows the typical layout of a simple computer's program memory with the text, various data, and stack and heap sections.

The data segment contains initialized static variables, i.e. global variables and local static variables which have a defined value and can be modified. Examples in C include:

int i = 3;
char a[] = "Hello World";
static int b = 2023;    // Initialized static global variable
void foo (void) {
  static int c = 2023; // Initialized static local variable
}

BSS

The BSS segment contains uninitialized static data, both variables and constants, i.e. global variables and local static variables that are initialized to zero or do not have explicit initialization in source code. Examples in C include:

static int i;
static char a[12];

Heap

The heap segment contains dynamically allocated memory, commonly begins at the end of the BSS segment and grows to larger addresses from there. It is managed by malloc, calloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single heap segment is not required to fulfill the contract of malloc/calloc/realloc/free; they may also be implemented using mmap/munmap to reserve/unreserve potentially non-contiguous regions of virtual memory into the process' virtual address space). The heap segment is shared by all threads, shared libraries, and dynamically loaded modules in a process.

Stack

The stack segment contains the call stack, a LIFO structure, typically located in the higher parts of memory. A "stack pointer" register tracks the top of the stack; it is adjusted each time a value is "pushed" onto the stack. The set of values pushed for one function call is termed a "stack frame". A stack frame consists at minimum of a return address. Automatic variables are also allocated on the stack.

The stack segment traditionally adjoined the heap segment and they grew towards each other; when the stack pointer met the heap pointer, free memory was exhausted. With large address spaces and virtual memory techniques they tend to be placed more freely, but they still typically grow in a converging direction. On the standard PC x86 architecture the stack grows toward address zero, meaning that more recent items, deeper in the call chain, are at numerically lower addresses and closer to the heap. On some other architectures it grows the opposite direction.

Interpreted languages

Some interpreted languages offer a similar facility to the data segment, notably Perl[1] and Ruby.[2] In these languages, including the line __DATA__ (Perl) or __END__ (Ruby, old Perl) marks the end of the code segment and the start of the data segment. Only the contents prior to this line are executed, and the contents of the source file after this line are available as a file object: PACKAGE::DATA in Perl (e.g., main::DATA) and DATA in Ruby. This can be considered a form of here document (a file literal).

See also

References

  • "C startup". bravegnu.org.
  • "mem_sequence.c - sequentially lists memory regions in a process". Archived from the original on 2009-02-02.
  • van der Linden, Peter (1997). Expert C Programming: Deep C Secrets (PDF). Prentice Hall. pp. 119ff.

Read other articles:

Siklopentana Nama Nama IUPAC Siklopentana Nama lain pentametilena Penanda Nomor CAS 287-92-3 Y Model 3D (JSmol) Gambar interaktif 3DMet {{{3DMet}}} ChEBI CHEBI:23492 Y ChemSpider 8896 Y Nomor EC PubChem CID 9253 Nomor RTECS {{{value}}} CompTox Dashboard (EPA) DTXSID6024886 InChI InChI=1S/C5H10/c1-2-4-5-3-1/h1-5H2 YKey: RGSFGYAAUTVSQA-UHFFFAOYSA-N YInChI=1/C5H10/c1-2-4-5-3-1/h1-5H2Key: RGSFGYAAUTVSQA-UHFFFAOYAL SMILES C1CCCC1 Sifat Rumus kimia C5H10 Ma...

 

 

Peta wilayah Asia Pasifik Asia-Pasifik adalah wilayah yang mencakup Asia Timur, Asia Tenggara, Asia Selatan, Asia Tengah, Asia Barat dan Australasia di dekat Laut Pasifik, ditambah negara-negara di laut Pasifik (Oceania). Walaupun deskripsi geografis kurang tepat, istilah Asia-Pasifik menjadi dikenal pada sekitar tahun 1980-an sewaktu pertumbuhan ekonomi pada wilayah heterogen ini dalam hal perdagangan saham, perdagangan umum dan bentuk lain dari interaksi ekonomi dan politik menjadi topik pe...

 

 

Diplomatic crisis over nuclear weapons 1994 North Korean nuclear crisisPart of Inter-Korean conflictFlight Operations aboard the USS Kitty Hawk on 4 December 1994Date12 March 1993 – 21 October 1994LocationKorean PeninsulaSea of JapanResult Agreed Framework signed between United States and North Korea Temporary suspension of North Korean nuclear weapons program Cessation of Team Spirit exercisesBelligerents  North Korea  United States South KoreaCommanders and leaders Kim Il S...

Yuan dynasty silk painting Sermon on Mani's Teaching of SalvationChinese: 冥王聖幀ArtistUnknownYear13th centuryTypeHanging scroll, paint and gold on silkDimensions142.0 cm × 59.2 cm (55.9 in × 23.3 in)LocationMuseum of Japanese Art, Nara Sermon on Mani's Teaching of Salvation (Chinese: 冥王聖幀; lit. 'Sacred Scroll of the King of the Underworld') is a Yuan dynasty silk hanging scroll, measuring 142 × 59 centimetres and dating fr...

 

 

此條目需要补充更多来源。 (2021年7月4日)请协助補充多方面可靠来源以改善这篇条目,无法查证的内容可能會因為异议提出而被移除。致使用者:请搜索一下条目的标题(来源搜索:美国众议院 — 网页、新闻、书籍、学术、图像),以检查网络上是否存在该主题的更多可靠来源(判定指引)。 美國眾議院 United States House of Representatives第118届美国国会众议院徽章 众议院旗...

 

 

此条目序言章节没有充分总结全文内容要点。 (2019年3月21日)请考虑扩充序言,清晰概述条目所有重點。请在条目的讨论页讨论此问题。 哈萨克斯坦總統哈薩克總統旗現任Қасым-Жомарт Кемелұлы Тоқаев卡瑟姆若马尔特·托卡耶夫自2019年3月20日在任任期7年首任努尔苏丹·纳扎尔巴耶夫设立1990年4月24日(哈薩克蘇維埃社會主義共和國總統) 哈萨克斯坦 哈萨克斯坦政府...

Android 4.4 KitKatVersi dari sistem operasi AndroidLayar awal Android 4.4.2PembangunGoogleDirilis kemanufaktur31 Oktober 2013; 10 tahun lalu (2013-10-31)Rilis terbaru4.4.4 KTU84Q[1] / 19 Agustus 2014; 9 tahun lalu (2014-08-19)Didahului olehAndroid 4.1.x, 4.2.x, 4.3.x Jelly BeanDigantikan olehAndroid 5.x LollipopSitus resmiSitus web resmiStatus dukunganTidak didukung sejak 2017, Layanan Google Play tidak didukung sejak Agustus 2023. Android 4.4 KitKat adalah versi dari sistem...

 

 

2017 studio album by Luis Miguel¡México Por Siempre!Studio album by Luis MiguelReleased24 November 2017 (2017-11-24)StudioUnited RecordingWestlake Recording Studios (Hollywood, CA)GenreMariachirancheraLength42:08LanguageSpanishLabelWarner Music MexicoProducerLuis MiguelLuis Miguel chronology Luis Miguel(2010) ¡México Por Siempre!(2017) Singles from ¡México por siempre! La Fiesta del MariachiReleased: 27 October 2017[1] LlamaradaReleased: 17 November 2017&...

 

 

1952 film Dancing StarsGerman film posterGermanTanzende Sterne Directed byGéza von CziffraWritten byGéza von CziffraProduced byOtto MeissnerGéza von CziffraStarringGermaine DamarGeorg ThomallaFita BenkhoffCinematographyGeorg BruckbauerEdited byAlice LudwigMusic byMichael JaryProductioncompanyArion-FilmDistributed byHerzog-FilmverleihRelease date 27 November 1952 (1952-11-27) Running time94 minutesCountryWest GermanyLanguageGerman Dancing Stars (German: Tanzende Sterne) is a ...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أغسطس 2014) ليلة عيد الحبمعلومات عامةالصنف الفني رومانسية , كوميديا , إثارةتاريخ الصدور 10 فبراير 2012اللغة الأصلية هنديةالبلد الهندموقع الويب timesofindia.indiatimes.com… الطاقمالم�...

 

 

Cet article est une ébauche concernant l’histoire. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Plaque évoquant le traité du Fleix, à l'intérieur du temple du Fleix. La paix du Fleix, connue aussi sous le nom de convention ou conférence du Fleix, ou de paix des amoureux, qui fut signée le 26 novembre 1580, a mis fin à la septième guerre de Religion. Elle est proclamée à Montaigu[Lequel ?...

 

 

У этого термина существуют и другие значения, см. Корниловка и Кирово. СелоКорниловкаукр. Корнилівка Флаг Герб 49°29′10″ с. ш. 31°20′14″ в. д.HGЯO Страна  Украина Область Черкасская Район Корсунь-Шевченковский История и география Основан неизвестно Прежние назван...

IÉSEG School of ManagementHistoireFondation 1964StatutType École supérieure de commerce privéeForme juridique Association déclarée (d)Nom officiel Institut d'économie scientifique et de gestionRégime linguistique Anglais, FrançaisFondateur Michel FalisePrésident Christophe CatoirDirecteur Caroline RousselDevise Empowering changemakers for a better society (« Donner le pouvoir aux acteurs de changement pour une société meilleure »)Membre de Université catholique de Lil...

 

 

1st-century Roman military commander and writer Pliny the ElderGaius Plinius Secundus19th-century illustration of PlinyBornAD 23/24Novum Comum, Italia, Roman EmpireDiedAD 79 (aged 55)Stabiae, Italia, Roman EmpireCitizenshipRomanEducationRhetoric, grammarOccupation(s)Lawyer, author, natural philosopher, historian, naturalist, military commander, provincial governorNotable workNaturalis HistoriaChildrenPliny the Younger (nephew, later adopted son)Parent(s)Gaius Plinius Celer and Marcella Gaius ...

 

 

Запрос «Пугачёвщина» перенаправляется сюда; о сборнике документов см. Пугачёвщина (сборник документов). Восстание Пугачёва В. Г. Перов. Суд Пугачёва. 1875 Дата 17 (28) сентября 1773 — середина 1775 (активные боевые действия до конца 1774) Место Оренбургская, Сибирская (западн�...

American baseball player Baseball player Ben HolmesThird basemanBorn: (1858-04-03)April 3, 1858King and Queen County, VirginiaDied: May 11, 1949(1949-05-11) (aged 91)Washington, DCNegro league baseball debut1886, for the Cuban GiantsLast appearance1891, for the Cuban Giants Teams Cuban Giants (1886–1888, 1891) Benjamin F. Holmes (April 3, 1858 – May 11, 1949) was an American Negro league third baseman in the 1880s and 1890s. A native of King and Queen County, Virg...

 

 

Tool to clear blockages in drains and pipes This article is about the plumbing tool. For other uses, see Plunger (disambiguation). Plumbing plunger A plunger is a device driven by or against fluid pressure.[1] In plumbing, the term plunger commonly refers to handheld tools used to clear blockages in drains and pipes. Plumbing plungers consist of a rubber suction cup attached to a stick (shaft) usually made of wood or plastic. A different bellows-like design also exists, usually constr...

 

 

Language native to Australia This article may require cleanup to meet Wikipedia's quality standards. The specific problem is: Need to remove inappropriate bolding and use {{lang}} to tag non-English text and put it in italics. Please help improve this article if you can. (February 2019) (Learn how and when to remove this message) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced mat...

خجندة منظر لنهر -مدينة خجند  علم شعار الاسم الرسمي خجندة الإحداثيات 40°17′N 69°38′E / 40.283°N 69.633°E / 40.283; 69.633 تقسيم إداري  الدولة طاجيكستان  الولاية صغد عاصمة لـ صغد  خصائص جغرافية  المساحة 40 كيلومتر مربع  ارتفاع 300 متر  عدد السكان (2000)  المجموع 149...

 

 

Statue in bronze of naturalist Alfred Russel Wallace (1823-1913) by Anthony Smith. He is looking up at a bronze model of a Wallace's golden birdwing butterfly (Ornithoptera croesus). The statue was commissioned by the Wallace Memorial Fund and was given to the Natural History Museum, London, where it was unveiled by Sir David Attenborough on November 7th 2013 - the 100th anniversary of Wallace's death.[1] The centenary of the death of the naturalist Alfred Russel Wallace on 7 November...