answersLogoWhite

0


Best Answer

Types cannot share memory; only instances of a type (objects or variables) can share memory. This is achieved through the use of shared resource handles or "smart pointers". We can also use C-style pointer variables to share memory, however they are problematic because as soon as the shared memory is released, all pointers to it become invalid but there's no way to tell if a pointer is valid or not. Even without using shared memory, there is no notion of "ownership" as far as pointers are concerned.

In the absence of resource handles, the best strategy is to allocate memory in an outer scope and then create shared pointers within an inner scope. The shared pointers MUST NOT release the memory they refer to. When we return to the outer scope, the shared references will have fallen from scope, thus we can safely release the memory using the same pointer variable we used to allocate the memory. In this way we get some notion of ownership.

With resource handles we don't have this problem because the shared memory cannot be released accidently until the very last reference falls from scope. The last reference need not be the one we originally used to allocate the memory.

Sharing memory between threads is best kept to an absolute minimum. Although we can use locks to prevent data races, we achieve better performance with lock-free code and there's less risk of deadlock (where two threads are waiting on each other to release the memory they've locked). Shared memory is often unavoidable, but don't use it just because you can, only use it when it is appropriate to do so; there are always alternatives.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which data type perimits sharing memory among different types of data?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between parallel and distrtibuted opering system?

parallel operating system is tha sharing of data between two computers....... Distributing system is the sharing of data among different computers....


Operating system as resource manager?

This is an alternate view about the services performed by the OS. The OS system provides an orderly and controlled allocation of the processors, memories and I/O devices. When a computer has multiple users the need for managing and protecting the memory, I/O devices and other devices is greater. Thus the primary task of OS is to keep track of who is using which resource, to grant resource requests, to mediate conflicting requests from different programs etc. Resource management includes multiplexing resources in two ways - "in time" and "in space". (i)When a resource is time multiplexed different programs or different users gets their turn to use that resource. eg: Printer. (ii)When a resource is space multiplexed instead of taking turns, the resource is shared among them, ie each one gets a part of the resource. eg: Sharing main memory, hard disk etc.


What did Berners-Lee hope to achieve when he invented hypertext?

Tim Berners-Lee hoped to facilitate sharing and updating among researchers with his project based on the concept of hypertext.


How many objects of a given class can there be in a program?

It depends on the size of the object and the amount of (virtual) memory available. However, the size of an object is not determined by the amount of memory it physically occupies, but by the amount of memory it consumes. For example, a resource handle object occupies at least one word of memory, but the resource it refers to consumes additional memory. The sizeof operator only returns the size of memory occupied by the object itself, not the total memory consumed by the object.


What is memory protection?

The protection of memory allocated to one program from unauthorized access by another program is called memory protection. It may refer to protection among various programs in a multi tasking environment or in between OS and a program in a single tasking environment. It is needed to prevent a bug within a process from affecting other processes. It also prevents system crash in case of error on OS.

Related questions

What is the different form of power sharing?

power shared between different organs of government(horizontal power sharing) power shared between different levels of government(vertical power sharing) power shared among different social groups power shared among different political parties,pressure groups,etc


What are the advantages of horizontal power sharing?

The power that is shared among different organs of government equally checking and balancing each other is horizontal power sharing


What does the term power sharing signify?

Power sharing signifies the sharing or dividing of power within the country among different religious and cultural communities in order to prevent disputes on social or political lines and so that all are treated equally and the goal of democracy is achieved.


What is the difference between parallel and distrtibuted opering system?

parallel operating system is tha sharing of data between two computers....... Distributing system is the sharing of data among different computers....


What is the difference between vertical and horizontal power sharing?

Horizontal Power sharing 1. Under the horizontal power sharing power is shared among different organs of government such as the legislature, executive and judiciary. 2. Under horizontal distribution of power, organs of the government are placed at the same level to exercise different powers. 3. Under horizontal each organ checks the other. Vertical Power sharing 1. Under the vertical sharing power, power is shared among the different levels of the governments. 2. The vertical division of power involves the highest and the lower levels of government. 3. Under vertical power sharing the lower organs work under the higher org.


What part of speech is the word among?

The word among is a preposition. It refers to a sharing of a common feature.


What is the word for Sharing the hotel bill among friends?

Splitting.


What is powersharing?

sharing of powers among the representatives elected in elections.


When two or more different kinds of atoms bond is called?

its can be the ionic, covalent or metallic bond as all these bonds can be among either the same or different atoms as it relate only to tranferring or sharing electrons....


What is meant by diagonal communication?

The sharing of information among different structural levels within a business. Diagonal communication offers employees the opportunity to communicate effectively with the organizational hierarchy.


What are the difficulties of power sharing?

Difficulties of power sharing can include challenges in reaching consensus among different groups, potential for conflict over distribution of power, and concerns about the effectiveness and efficiency of decision-making processes. Additionally, power sharing may require compromises that can be difficult for some parties to accept, leading to tensions and resistance.


Which among the following refers to the memory in your computer?

RAM