167:
394:
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
91:
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
386:
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
86:
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
293:
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:
124:. 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
424:(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:
399:
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.
95:
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.
352:
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
104:
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
92:
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.
178:
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:
543:
340:
contains dynamically allocated memory, commonly begins at the end of the BSS segment and grows to larger addresses from there. It is managed by
79:, also known as the text segment, which is read-only on many architectures. Uninitialized data, both variables and constants, is instead in the
132:
segments of the program, and the remainder which could be written to divided into a number of other segments for specific tasks.
170:
This shows the typical layout of a simple computer's program memory with the text, various data, and stack and heap sections.
51:. The size of this segment is determined by the size of the values in the program's source code, and does not change at
52:
58:
The data segment is read/write, since the values of variables can be altered at run time. This is in contrast to the
578:
360:). The heap segment is shared by all threads, shared libraries, and dynamically loaded modules in a process.
117:
413:
583:
479:
556:
547:
515:
356:/munmap to reserve/unreserve potentially non-contiguous regions of virtual memory into the process'
331:
474:
484:
449:
357:
48:
8:
503:
459:
454:
388:
531:
396:
383:
105:
75:), which contains static constants rather than variables; it also contrasts to the
408:
Some interpreted languages offer a similar facility to the data segment, notably
44:
40:
572:
437:
36:
464:
141:
76:
284:
80:
32:
166:
379:
369:
155:
88:
20:
109:
544:"mem_sequence.c - sequentially lists memory regions in a process"
341:
121:
113:
469:
409:
353:
349:
345:
570:
158:code and is generally read-only and fixed size.
344:, calloc, realloc, and free, which may use the
554:
436:in Ruby. This can be considered a form of
416:. In these languages, including the line
403:
165:
39:of a program that contains initialized
571:
231:// Initialized static global variable
558:Expert C Programming: Deep C Secrets
270:// Initialized static local variable
13:
14:
595:
524:
391:are also allocated on the stack.
99:
564:. Prentice Hall. pp. 119ff.
555:van der Linden, Peter (1997).
508:
497:
395:direction. On the standard PC
1:
490:
7:
443:
10:
600:
504:perldata: Special Literals
480:Stack (abstract data type)
367:
329:
282:
139:
363:
332:Manual memory management
296:
180:
579:Executable file formats
325:
207:"Hello World"
161:
135:
475:Uninitialized variable
278:
171:
60:read-only data segment
49:static local variables
485:Process control block
450:Segmentation (memory)
404:Interpreted languages
358:virtual address space
169:
35:or the corresponding
31:) is a portion of an
389:Automatic variables
460:Linker (computing)
455:Segmentation fault
440:(a file literal).
172:
584:Memory management
591:
565:
563:
551:
546:. Archived from
539:
518:
512:
506:
501:
435:
431:
427:
423:
419:
397:x86 architecture
321:
318:
315:
312:
309:
306:
303:
300:
274:
271:
268:
265:
262:
259:
256:
253:
250:
247:
244:
241:
238:
235:
232:
229:
226:
223:
220:
217:
214:
211:
208:
205:
202:
199:
196:
193:
190:
187:
184:
150:, also known as
106:read-only memory
68:
67:
45:global variables
41:static variables
599:
598:
594:
593:
592:
590:
589:
588:
569:
568:
561:
542:
530:
527:
522:
521:
513:
509:
502:
498:
493:
446:
433:
429:
428:in Perl (e.g.,
425:
421:
417:
406:
372:
366:
334:
328:
323:
322:
319:
316:
313:
310:
307:
304:
301:
298:
287:
281:
276:
275:
272:
269:
266:
263:
260:
257:
254:
251:
248:
245:
242:
239:
236:
233:
230:
227:
224:
221:
218:
215:
212:
209:
206:
203:
200:
197:
194:
191:
188:
185:
182:
164:
144:
138:
102:
65:
64:
27:(often denoted
17:
16:Storage segment
12:
11:
5:
597:
587:
586:
581:
567:
566:
552:
550:on 2009-02-02.
540:
526:
525:External links
523:
520:
519:
514:Ruby: Object:
507:
495:
494:
492:
489:
488:
487:
482:
477:
472:
467:
462:
457:
452:
445:
442:
405:
402:
368:Main article:
365:
362:
330:Main article:
327:
324:
297:
283:Main article:
280:
277:
181:
163:
160:
140:Main article:
137:
134:
101:
100:Program memory
98:
15:
9:
6:
4:
3:
2:
596:
585:
582:
580:
577:
576:
574:
560:
559:
553:
549:
545:
541:
537:
533:
529:
528:
517:
511:
505:
500:
496:
486:
483:
481:
478:
476:
473:
471:
468:
466:
463:
461:
458:
456:
453:
451:
448:
447:
441:
439:
438:here document
426:PACKAGE::DATA
415:
411:
401:
398:
392:
390:
385:
381:
378:contains the
377:
376:stack segment
371:
361:
359:
355:
351:
347:
343:
339:
333:
295:
292:
286:
179:
177:
168:
159:
157:
153:
149:
143:
133:
131:
127:
123:
119:
115:
111:
107:
97:
93:
90:
84:
82:
78:
74:
70:
61:
56:
54:
50:
46:
42:
38:
37:address space
34:
30:
26:
22:
557:
548:the original
536:bravegnu.org
535:
510:
499:
465:Code segment
407:
393:
375:
373:
338:heap segment
337:
335:
290:
288:
176:data segment
175:
173:
152:text segment
151:
148:code segment
147:
145:
142:Code segment
129:
125:
103:
94:
85:
77:code segment
72:
63:
59:
57:
28:
25:data segment
24:
18:
532:"C startup"
291:BSS segment
285:BSS segment
154:, contains
81:BSS segment
43:, that is,
33:object file
573:Categories
491:References
430:main::DATA
420:(Perl) or
380:call stack
370:Call stack
156:executable
89:Intel 8086
387:address.
21:computing
444:See also
418:__DATA__
110:Mask ROM
108:such as
53:run time
516:__END__
422:__END__
130:.rodata
73:.rodata
69:segment
432:) and
342:malloc
311:static
299:static
252:static
213:static
122:EEPROM
66:rodata
562:(PDF)
364:Stack
126:.text
114:EPROM
29:.data
470:.bss
434:DATA
414:Ruby
412:and
410:Perl
384:LIFO
382:, a
374:The
354:mmap
350:sbrk
348:and
336:The
326:Heap
314:char
289:The
264:2023
243:void
234:void
225:2023
198:char
174:The
162:Data
146:The
136:Code
128:and
118:PROM
47:and
23:, a
346:brk
302:int
279:BSS
255:int
237:foo
216:int
183:int
120:or
71:or
19:In
575::
534:.
116:,
112:,
83:.
55:.
538:.
320:;
317:a
308:;
305:i
273:}
267:;
261:=
258:c
249:{
246:)
240:(
228:;
222:=
219:b
210:;
204:=
201:a
195:;
192:3
189:=
186:i
62:(
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.