Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / January 2007

Tip: Looking for answers? Try searching our database.

What is a *Page*?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Abubakar - 19 Jan 2007 15:34 GMT
Hi,

I'm viewing this stack overflow help page (
http://support.microsoft.com/kb/315937 ) at the ms support site. I cant say
I understand the concept of a "page" the way its used in this
example/explanation. I mean I only am aware of the *simple*, *general*,
paging concept, the one that is discussed often when explaning how an
operating system can support more memory than actually is available by doing
paging on the hard drive (and that also only at a higher-level theoratical
concept). Although the "page"/"page guard"/etc thats referenced here *feels*
something like that but nothing makes sense to me.
For example take this sentence:

"The stack then grows on demand to meet the needs of the thread. This is
implemented by placing a page with PAGE_GUARD access at the end of the
current stack."

here I'm confused.
- What is a "page" here? Is it some data structure? What do they contain?
Can we see it? Is it documented? I need the links to its docs.

- is "stack" some linked list kind of dynamically growing LIFO data
structure? Are the contents of this stack these (unknown for me) "pages", in
which case if the stack size is 5 than there will be 5 pages?

plz clarify...
Regards,

..ab
William DePalo [MVP VC++] - 19 Jan 2007 16:32 GMT
> here I'm confused.
> - What is a "page" here? Is it some data structure? What do they contain?
> Can we see it? Is it documented? I need the links to its docs.

On an operating system that uses virtual memory, a page is the smallest
amount of memory which is moved in one go from the page file to physical
memory. If you need to know how much memory is in a page, you call
GetSystemInfo().

> - is "stack" some linked list kind of dynamically growing LIFO data
> structure?

No. The stack is a contiguous region of memory. By default, it is 1MB large.
But like every other region of memory in Windows it is virtual memory.
Address ranges of memory in the stack region are backed ("committed") by
physical memory on an as needed basis.

> Are the contents of this stack these (unknown for me) "pages", in which
> case if the stack size is 5 than there will be 5 pages?

It's a rare application which measures the size of anything in pages. The
stack is no different, it is measured in bytes.

Why do you need to know?

Regards,
Will
Abubakar - 20 Jan 2007 10:48 GMT
Hi,
thanks for the nice explanation.

> Why do you need to know?

Well, I was going through the kb site on microsoft support and it showed how
I could catch the stack overflow exception and handle it and the talk was
all about "pages". I have heard about pages before but I thought that
finally I need to remove my confusion and build up some knowledge about this
concept so I wont have any confusions in the future when somebody mentions
"stack" or "pages" or "heap" etc.

If u find/know any links related to these concepts, do share here.

Regards,

..ab

>> here I'm confused.
>> - What is a "page" here? Is it some data structure? What do they contain?
[quoted text clipped - 23 lines]
> Regards,
> Will
William DePalo [MVP VC++] - 20 Jan 2007 17:47 GMT
> thanks for the nice explanation.

You are welcome.

> Well, I was going through the kb site on microsoft support and it showed
> how I could catch the stack overflow exception and handle it and the talk
> was all about "pages". I have heard about pages before but I thought that
> finally I need to remove my confusion and build up some knowledge about
> this concept so I wont have any confusions in the future when somebody
> mentions "stack" or "pages" or "heap" etc.

Well, first you have to remember that the stack by deafult is 1MB large.
Your application shouldn't have to worry in general about overflowing the
stack. If it does overflow it, that's generally due to one of two main
causes:

1) a recursive algorithm recursing too much <g>
2) the allocation of a very large "automatic" array on the stack

One deals with the first problem by recasting an algorithm, and with the
second by moving the allocation to the heap.

Regards,
Will
Doug Harrison [MVP] - 19 Jan 2007 17:21 GMT
>Hi,
>
[quoted text clipped - 16 lines]
> - What is a "page" here? Is it some data structure? What do they contain?
>Can we see it? Is it documented? I need the links to its docs.

A page is the smallest unit of memory the Windows virtual memory system
deals with. Look up VirtualAlloc, and you'll find a lot of info on pages.

> - is "stack" some linked list kind of dynamically growing LIFO data
>structure?

No, a thread's stack is a contiguous region of memory that grows
dynamically up to its maximum configured size as the thread pushes data
into the guard page, which causes a structured exception, which further
causes the OS to commit the page and create a new guard page just below it.

>Are the contents of this stack these (unknown for me) "pages", in
>which case if the stack size is 5 than there will be 5 pages?

It's a lot more common to measure in bytes; when there's doubt, you should
specify the units, as I'm sure the Mars Climate Orbiter people wish they
had done.

You should search MSDN for PAGE_GUARD. This article talks about it, but its
example doesn't illustrate using it to grow a stack:

http://msdn2.microsoft.com/en-us/library/aa366549.aspx

This one talks about reserving and committing memory and shows how to use
structured exceptions to handle page faults to grow an array:

http://msdn2.microsoft.com/en-us/library/aa366803.aspx

What the system does with the thread stack lies somewhere in between...

Signature

Doug Harrison
Visual C++ MVP

Abubakar - 20 Jan 2007 10:39 GMT
Hey thanks for the useful links and the explanation. I'll have to read a lot
before being able to ask more on this topic.

Regards,

..ab

>>Hi,
>>
[quoted text clipped - 51 lines]
>
> What the system does with the thread stack lies somewhere in between...
Ben Voigt - 22 Jan 2007 15:04 GMT
> Hi,
>
[quoted text clipped - 8 lines]
> referenced here *feels* something like that but nothing makes sense to me.
> For example take this sentence:

While a emulating additional memory using a swap file uses paging as its
implementation (in most OSes, including Windows), it is not the definition
of paging/virtual memory.  It's extremely useful for isolating user-mode
processes from each other for security and reliability, and dynamic memory
commitment.  A good place to start is by reading up on virtual memory and
the Translation Look-aside Buffer (TLB).

http://en.wikipedia.org/wiki/Virtual_memory
http://en.wikipedia.org/wiki/Page_fault
http://en.wikipedia.org/wiki/Page_table
http://en.wikipedia.org/wiki/Translation_Lookaside_Buffer

> "The stack then grows on demand to meet the needs of the thread. This is
> implemented by placing a page with PAGE_GUARD access at the end of the
[quoted text clipped - 12 lines]
>
> ..ab
Abubakar - 31 Jan 2007 04:50 GMT
Thanks.

..ab

>> Hi,
>>
[quoted text clipped - 38 lines]
>>
>> ..ab

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.