Click here to Skip to main content
15,909,503 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hI Can anybody tell me that :
How do strings in .net( or java) gets stored...in a contigious memory location OR anywhere (if it does not find a contingious location) .

thx in advance
Posted
Comments
BobJanova 1-Jul-11 10:02am    
Why do you care? As a high level language in a garbage collected environment, it makes no difference to you how they are stored. You can use members of the Marshal class if you require particular memory storage strategies for communication with unmanaged libraries.

The nature of memory allocation is that the allocated block of memory is continguous. Once deallocated, it may never be used again by the application. Back in the day, this could call something known as "heap fragmentation", and would generally crash a program if that program needed to allocate a block of memory had been running long enough to effectively leave no blocks of memory large enough to satisfy the necessary allocation.

.Net's garbage collector is supposed to remedy that problem. Regarding javascript, I don't know the nature of it regarding garbage collecting and heap recovery.
 
Share this answer
 
v2
Comments
shikhar gilhotra 1-Jul-11 8:01am    
thnks for your comments....please answer the second part of my query..
BobJanova 1-Jul-11 10:00am    
Javascript is also supposed to be garbage collected. The OP was asking about Java though which definitely has a similar mechanism to .Net.
Sergey Alexandrovich Kryukov 2-Jul-11 4:14am    
This is even more non-trivial. Please see my answer.
--SA
As to .NET, string is a reference class thoroughly mimicking value semantic. It's storage is quite non-trivial, based on the idea of interning.

Please see recent answers on related topic, including mine, here: string is a reference type or value type[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900