In my program i have one static block and i created 2 objects .. i think each object maintains different stack ?? am i right ..
can you please explain me the exact storage mechanism ?? is stack OS dependent ?? whats that exactly .
Share ur view in your own words plzz :)
Thank you

VulpesPosted Apr 8, 2013, 6:00 AM
VulpesPosted Apr 8, 2013, 4:24 PM
SUNIL GUTTAPosted Apr 8, 2013, 3:38 PM
Coming to threads humm i said same about this to my friend , he said stupidly or intelligently like this , Under main method or function in c++ when we created 2 threads they occupies memory in stack via frames not as separate stacks :( he said thread is a process --> process is a function to do i.e for doing function we create objects and if we create objects when we bind with data members will be allocated in stack or heap in frames not in separate stacks ??
Well earlier i said there exists 1mb stack only for .net app's .. so how come there exists multiple stacks for it like 1mb stack for each thread ?? .. incase if we using same stack for n threads cant we call as stack frame like before we done in class instances :)
VulpesPosted Apr 8, 2013, 3:09 PM
So, if multiple threads have been created and are active, then there will be multiple stacks but each stack could contain any number of stack frames depending on how many methods have been called on that thread and have not yet returned.
If you want a detailed knowledge of how .NET works internally, then this is a good book to start from:
http://www.amazon.com/CLR-via-Microsoft-Developer-Reference/dp/0735667454
SUNIL GUTTAPosted Apr 8, 2013, 2:44 PM
Well how come you mastered upto this level any specific way to do so ?? Being a electronics i made my choice towards Software field quite lately but i am connected very well with it :)
So want to be as good as anyone :) just tell me how :) any books,strategies 2 prepare etc
VulpesPosted Apr 8, 2013, 9:40 AM
SUNIL GUTTAPosted Apr 8, 2013, 6:54 AM
As my sir told in ATM machines when we swipe card the object will be created for us , if so there will be heap & stack in ATM machines for sure for object storage :)
Hackers are ready to hack the object so that they can get pin or imp info that means they are getting access to stack memory ?? is stack via heap memory readable ?
One more doubt on stack ? It looks crazy but do calrify
-Well i said stack has 1mb size . for each object stack frame is allocated say i have created 2 objects under Main . 1ST object stores in say addr from 0000-0003 . when next object is created does it occupy immediate next stack frame .?? if so were is the security for object ?? we can get info of object to using obj one ?? encapsulation breaking right ? sorry if i am over smart or fool with my silly doubts :)
TY
SUNIL GUTTAPosted Apr 8, 2013, 4:58 AM
So well lets say in multi-threading concept with one MAIN method there i created multiple threads using NEW keyword . . . As we speak each thread takes one stack (reference in heap) i.e so in my program there exists multiple threads so there will be multiple stacks right ??
if so
As i used NEW keyword for creation of threads it is just like creating different objects under class for data members ?? what's the difference ?
As each object of a class is independent of each other so why cant they share a seperate stack memory as they do in threads //
Is stack allocation is dependent on MAIN () ??
If miss something do clarify me . sorry for confusion created towards u :(
Ty for support
VulpesPosted Apr 6, 2013, 4:02 PM
The default size of a stack in .NET is 1 megabyte.
The number of stacks in a .NET application has nothing to do with how many objects are created in that application. It simply depends on the number of threads in existence at any one time as mentioned in my earlier post.
All code in the Main() method of a .NET application will run on the main or start-up thread. The position is exactly the same with the main() function under a C++ application.
However, in .NET objects (i.e. instances of classes) are never created on the stack itself - they are created on the heap and class variables stored on the stack just contain references to them.
In contrast, objects in C++ can be created either on the heap or on the stack.
So what your friend said about the main() function is essentially correct though the stack is only under the control of the OS to the extent that it's contained within the memory allocated by it to a process and because the OS (ultimately) controls thread allocation and scheduling.
SUNIL GUTTAPosted Apr 6, 2013, 3:00 PM
Can you please explain me in detail . like in terms Do operating system own STACK ?? if so how many stacks it will have ? stack memory size (32-bit) ?? ..
Coming to main point there will be n stacks for n objects right ?? Do all stacks share same memory in ONE STACK memory under control of OS if exists (i donno it exists single or multiple) . . .
Hope u got my trouble ?
-actually my friend said in c++ all functions take n objects under Main share same stack (single main single stack). He asked me & i said in c# terms well each object and its calling members share unique stack memory :) He in-turn turned down my argument i am wrong & said what ever the language, STACK is under control of OS said blah blah ??
- so whats happening who is ri8 & wrong and ur view :)
VulpesPosted Apr 6, 2013, 10:53 AM
So, in a single-threaded application, there's just one stack.