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:

Agricultural methods that capture carbon Measuring soil respiration on agricultural land Carbon farming is a name for a variety of agricultural methods aimed at sequestering atmospheric carbon into the soil and in crop roots, wood and leaves. The aim of carbon farming is to increase the rate at which carbon is sequestered into soil and plant material with the goal of creating a net loss of carbon from the atmosphere.[1] Increasing a soil's organic matter content can aid plant growth, ...

 

 

Село Олеснічкапол. Oleśniczka Координати 51°08′35″ пн. ш. 17°16′54″ сх. д. / 51.1433333300277724° пн. ш. 17.281666670028° сх. д. / 51.1433333300277724; 17.281666670028Координати: 51°08′35″ пн. ш. 17°16′54″ сх. д. / 51.1433333300277724° пн. ш. 17.281666670028° сх. д. / 51.143333330027...

 

 

Haakon Ellingsen kan verwijzen naar: Haakon Ellingsen (zanger), Noors singer-songwriter. Haakon Ellingsen (roeier), Noors roeier. Bekijk alle artikelen waarvan de titel begint met Haakon Ellingsen of met Haakon Ellingsen in de titel. Dit is een doorverwijspagina, bedoeld om de verschillen in betekenis of gebruik van Haakon Ellingsen inzichtelijk te maken. Op deze pagina staat een uitleg van de verschillende betekenissen van Haakon Ellingsen en verwijzingen daarnaartoe...

У Вікіпедії є статті про інших людей із прізвищем Тупак Амару (значення). Тупак АмаруTupaq AmaruTupaq Amarö Тупак Амару Сапа Інка, правитель держави інків 1571 — 1572 Попередник: Тіто Кусі Юпанкі Спадкоємець: (відсутній)   Народження: 1545(1545)Вількабамба Смерть: 1572(1572)Куско Причина...

 

 

يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (فبراير 2016) قامت الولايات المتحدة بتجميد أرصدة اليابان في 1941 حيث قام الرئيس فرانكلين روزفلت رئيس الولايات المتحدة ب...

 

 

The environmental impact of concrete, its manufacture, and its applications, are complex, driven in part by direct impacts of construction and infrastructure, as well as by CO2 emissions; between 4-8% of total global CO2 emissions come from concrete.[1] Many depend on circumstances. A major component is cement, which has its own environmental and social impacts and contributes largely to those of concrete. The cement industry is one of the main producers of carbon dioxide, a potent gr...

A Cube of Sugarیه حبه قندSampul DVDSutradara Seyyed Reza Mir-Karimi Produser Seyyed Reza Mir-Karimi Ditulis oleh Seyyed Reza Mir-Karimi Mohammad Reza Gohari PemeranNegar JavaherianSinematograferHamid Khozouie AbyanehTanggal rilis 8 Oktober 2011 (2011-10-08) (FFIB) Durasi116 menitNegara Iran Bahasa Farsi A Cube of Sugar (Persia: یک حبه قند, transkr. Yek Habe Ghand atau Ye Habe Ghand) adalah sebuah film drama Iran 2011 yang disutradarai oleh Seyyed Reza Mir-Karimi.&...

 

 

Nanien SudiarLahir4 Mei 1959 (umur 64)Bandung, IndonesiaPekerjaanaktris Nanien Sudiar (lahir 4 Mei 1959) adalah pemeran Indonesia. Ia, aktris lumayan terkenal lewat filmnya Remaja 76 yang cukup popular bagi masyarakat yang suka nonton bioskop pada waktu itu, dengan pemain Juni Arcan, Rd Mochtar, dan Nani Widjaja. Ia sempat menjadi peran utama dalam film Sebatang Kara, Anak Yang Menderita, dan Jalal Kojak Palsu. Filmografi Pandji Tengkorak (1971) Jangan Kau Tangisi (1972) Si Rano (1973) B...

 

 

GLSENTanggal pendirian1990PendiriKevin JenningsTipeKampanye Kesadaran Pemuda LGBT & Lembaga PendidikanLokasiNew York CityWilayah layanan Amerika SerikatDirektur eksekutifEliza ByardSitus webwww.glsen.org Nama sebelumnyaGay and Lesbian Independent School Teachers Network GLSEN (sebelumnya bernama Gay, Lesbian & Straight Education Network) adalah organisasi pendidikan berbasis di Amerika Serikat yang bekerja untuk mengakhiri diskriminasi, pelecehan, dan intimidasi berdasarkan orientasi ...

Large storm in Neptune's atmosphere The Great Dark Spot as seen from Voyager 2 The Great Dark Spot (also known as GDS-89, for Great Dark Spot, 1989) was one of a series of dark spots on Neptune similar in appearance to Jupiter's Great Red Spot. In 1989, GDS-89 was the first Great Dark Spot on Neptune to be observed by NASA's Voyager 2 space probe. Like Jupiter's spot, Great Dark Spots are anticyclonic storms. However, their interiors are relatively cloud-free, and unlike Jupiter's spot, which...

 

 

Politeknik Pertanian Negeri Pangkajene KepulauanNama sebelumnyaPoliteknik Pertanian Universitas HasanuddinJenisPerguruan Tinggi Negeri Politeknik NegeriDidirikan1989DirekturDr. Ir. H. Darmawan., MPLokasiPangkajene dan Kepulauan, Sulawesi Selatan, IndonesiaAlamatJl. Poros Makassar-Parepare KM. 83, Mandalle, Kabupaten Pangkajene dan KepulauanSitus webhttps://www.polipangkep.ac.id/ Politeknik Pertanian Negeri Pangkajene Kepulauan atau Polipangkep adalah sebuah perguruan tinggi negeri yang terdap...

 

 

This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. Please help to improve this article by introducing more precise citations. (January 2023) (Learn how and when to remove this template message) American TV series or program Kraft Music HallGenreMusical varietyCountry of originUnited StatesOriginal languageEnglishNo. of seasons13ProductionProduction locationsManhattan, New York City, New York, U...

Theoretical physicist Ilya LifshitzBornIlya Mikhailovich Lifshitz(1917-01-13)January 13, 1917Kharkiv, Kharkov Governorate, Russian EmpireDiedOctober 23, 1982(1982-10-23) (aged 65)Moscow, Soviet UnionAlma materUniversity of Kharkiv, Kharkiv Polytechnic InstituteKnown forLifshitz tailsLifshitz exponentLifshitz–Kosevich formulaLifshitz transitionSelf-averagingspectral shift functionsupersolidityAwardsLenin PrizeSimon Memorial Prize (1961)Scientific careerFieldsPhysicsInstitution...

 

 

Not to be confused with Yuki Ishikawa (wrestler, born 1995). Japanese professional wrestler, mixed martial artist and promoter Yuki IshikawaIshikawa in March 2020, at 16 Carat Gold, wrestling Daisuke IkedaBorn (1967-02-08) February 8, 1967 (age 56)Odawara, Kanagawa, JapanAlma materNihon UniversityProfessional wrestling careerRing name(s)Great Sasuke TigaYuki IshikawaBilled height180 cm (5 ft 11 in)Billed weight95 kg (209 lb)Trained byYoshiaki FujiwaraKarl GotchBo...

 

 

أولاد عمرو تقسيم إداري البلد المغرب  الجهة الشرق الإقليم بركان الدائرة أكليم الجماعة القروية رسلان المشيخة أولاد عبو السكان التعداد السكاني 372 نسمة (إحصاء 2004)   • عدد الأسر 62 معلومات أخرى التوقيت ت ع م±00:00 (توقيت قياسي)[1]،  وت ع م+01:00 (توقيت صيفي)[1]  تعديل مصد...

1999 single by Silkk the Shocker featuring MýaSomebody Like MeSingle by Silkk the Shocker featuring Mýafrom the album Made Man ReleasedFebruary 16, 1999Recorded1998GenreHip hop, R&BLength4:12LabelNo LimitPriorityEMISongwriter(s)Mýa Harrison Vyshonn Miller The Whole 9Producer(s)Master P (exec.) The Whole 9Silkk the Shocker singles chronology Movin' On (1998) Somebody Like Me (1999) Live or Die (1999) Mýa singles chronology Take Me There(1999) Somebody Like Me(1999) My First Nig...

 

 

Women's professional team golf tournament Not to be confused with Crown International. International CrownTournament informationLocationVaries2023 – San Francisco, CaliforniaEstablished2014Course(s)TPC Harding Park – (2023)Tour(s)LPGA TourFormatMatch play, team event32 players(4 each on 8 teams)Prize fund$2.0 millionMonth playedMayCurrent champion Thailand The Hanwha LifePlus International Crown is a biennial women's professional team golf tournament on the LPGA Tour. Eight national ...

 

 

Male OrjuleVele Orjule (left) and Male Orjule (right) from Sveti PetarGeographyLocationAdriatic SeaCoordinates44°29′25″N 14°33′51″E / 44.49028°N 14.56417°E / 44.49028; 14.56417ArchipelagoCres-LošinjArea0.33 km2 (0.13 sq mi)Highest elevation11 m (36 ft)AdministrationCroatiaDemographicsPopulation0 Male Orjule is an uninhabited Croatian island in the Adriatic Sea located southeast of Lošinj. Its area is 0.33 km2 (0.13 ...

This article is about the area of the Philippines. For the Spanish general, see Manuel Pavía y Lacy. This article contains close paraphrasing of a non-free copyrighted source, https://novalichesdiocese.org/spanish-era/ (Copyvios report). Relevant discussion may be found on the talk page. Please help rewriting it with your own words. (July 2021) (Learn how and when to remove this template message) Place in National Capital Region, PhilippinesNovalichesNovaliches Proper, Quezon CityCountryPhil...

 

 

DeenDeen in 2016BornFuad Backović (1982-04-12) 12 April 1982 (age 41)Sarajevo, SR Bosnia and Herzegovina, SFR YugoslaviaOccupation Singer Years active1996–2008; 2015–presentMusical careerGenres Pop Instrument(s) Vocals Musical artist Fuad Backović (born 12 April 1982), better known by his stage name Deen, is a Bosnian pop recording artist, reality star and fashion designer. Backović was the lead singer of the Bosnian boy band 7Up from 1997 until 2002, when he became a solo ar...

 

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!