Is the shared memory allocated irrelevant to the location?

Source: Internet
Author: User
18 what is the location-independent allocation of shared memory?

The ACE Programmer's Guide, The: Practical Design Patterns for Network and Systems Programming describes a location-independent shared memory allocation, however, this method is not ideal. According to the method described in this article, we mainly use the ALWAYS_FIXED parameter and the specified base address as the shared memory address. At the same time, the auxiliary class is used to ensure that two processes use the relative address to use the shared memory.

ACE_MMAP_Memory_Pool_Options options

(ACE_DEFAULT_BASE_ADDR,

ACE_MMAP_Memory_Pool_Options: ALWAYS_FIXED );

ACE_NEW_RETURN (g_allocator,

ALLOCATOR (BACKING_STORE,

BACKING_STORE,

& Options ),

-1 );

ACE_DEBUG (LM_DEBUG,

ACE_TEXT ("Mapped to base address % @/n "),

G_allocator-> base_addr ()));

 

Showrecords ();

 

However, you must first use the same base address, as shown in the example given by Ace. The default base address is a macro named "ace_default_base_addr" (0x80000000 in Linux ). Because address space management is the responsibility of the operating system, it is very unreliable to require two processes with the same shared memory to allocate the same base address. Using this method may have two consequences. First, if you want to use multiple shared memory, you need to calculate and manage the process space yourself. Second, your program has low portability, it may even appear on one machine and cannot run on another machine. Therefore, it is better to use this feature with caution. It is not a programmer's style to pin the Reliable Running of programs with good luck.

Therefore, for shared memory, if you want to achieve location-independent allocation, my personal advice is as follows:

L allocate enough space at the beginning and do not extend it. [note ]. Because the extended shared memory may mean that all the pointers related to the original shared memory will be invalid.

L each Process manages its own address space. Do not save any pointers in the shared memory (especially do not save pointers in the shared memory). All addresses use relative values. In this way, we can ensure that there is no problem with the basic address change.

 

Ace programmer's guide, the: Practical Design Patterns for network and systems programming also proposes processing shared memory pool encapsulation, however, all shared memory addresses must be adjusted. This method is not too accepted.

In addition, because Ace containers use pointers, we do not recommend using ace containers in shared memory.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.