2011-10-24 3 views
4

64 비트 응용 프로그램에서 SM을 만들고 32 비트 응용 프로그램에서 열면 실패합니다. 32 비트 프로그램에 의해 검색된 파일로의 경로에있을OSX에서 공유 메모리를 x86에서 x64로 또는 반대로 읽는 경우

/private/tmp/boost_interprocess/AD21A54E000000000000000000000000/test 

/private/tmp/boost_interprocess/AD21A54E00000000/test 

따라서 32 개 비트 어플리케이션이 읽을 수 : 64 비트 어플리케이션에 의해 작성된

//for 64 bit 
    shared_memory_object(create_only, "test" , read_write) ; 
// for 32 bit 
    shared_memory_object (open_only, "test", read_write); 

파일 아래의 경로에있을 파일.

Mac OS X에서 부스트 1.47.0을 사용하고 있습니다. 버그입니까? 일부 매크로를 사용하여 일부 설정을 수정해야합니까? 이전에이 문제가 발생 했습니까?

답변

1

문제의 해결책을 찾았는데 예상대로 버그입니다.

이 버그는 tmp_dir_helpers.hpp 파일에 있습니다. 이 있었어야으로이 같은 몇 가지 ..

**long long** fields[2] = { result.tv_sec, result.tv_usec }; 
      for(std::size_t field = 0; field != 2; ++field){ 
       for(std::size_t i = 0; i != sizeof(**long long**); ++i) 

내가이 버그에 대한 후원에 ticket을 만든

inline void get_bootstamp(std::string &s, bool add = false) 
    { 
     ... 
     std::size_t char_counter = 0; 
     long fields[2] = { result.tv_sec, result.tv_usec }; 
     for(std::size_t field = 0; field != 2; ++field){ 
      for(std::size_t i = 0; i != sizeof(long); ++i){ 
      const char *ptr = (const char *)&fields[field]; 
      bootstamp_str[char_counter++] = Characters[(ptr[i]&0xF0)>>4]; 
      bootstamp_str[char_counter++] = Characters[(ptr[i]&0x0F)]; 
      } 
     ... 
    } 

.

감사합니다.

1

공유 메모리를 파일로 백업하는 것이 중요합니까? 그렇지 않다면 sys/shm.h에 선언 된 shmget, shmat, shmdt 및 shmctl과 같은 기본 Unix 공유 메모리 API의 사용을 고려할 수 있습니다. 나는 그 (것)들을 사용하기 아주 쉽다 찾아 냈다.

// create some shared memory 
int id = shmget(0x12345678, 1024 * 1024, IPC_CREAT | 0666); 

if (id >= 0) 
{ 
    void* p = shmat(id, 0, 0); 

    if (p != (void*)-1) 
    { 
     initialize_shared_memory(p); 

     // detach from the shared memory when we are done; 
     // it will still exist, waiting for another process to access it 
     shmdt(p); 
    } 
    else 
    { 
     handle_error(); 
    } 
} 
else 
{ 
    handle_error(); 
} 

다른 프로세스가 공유 메모리에 액세스하기 위해이 같은 것을 사용하는 것이 : 모든 프로세스가 공유 메모리와 함께 완료되면 다음, 다시 시스템을 출시 할 shmctl(id, IPC_RMID, 0)를 사용

// access the shared memory 
int id = shmget(0x12345678, 0, 0); 

if (id >= 0) 
{ 
    // find out how big it is 
    struct shmid_ds info = { { 0 } }; 

    if (shmctl(id, IPC_STAT, &info) == 0) 
     printf("%d bytes of shared memory\n", (int)info.shm_segsz); 
    else 
     handle_error(); 

    // get its address 
    void* p = shmat(id, 0, 0); 

    if (p != (void*)-1) 
    { 
     do_something(p); 

     // detach from the shared memory; it still exists, but we can't get to it 
     shmdt(p); 
    } 
    else 
    { 
     handle_error(); 
    } 
} 
else 
{ 
    handle_error(); 
} 

.

명령 줄에서 ipcs 및 ipcrm 도구를 사용하여 공유 메모리를 관리 할 수 ​​있습니다. 처음 공유 메모리 코드를 작성할 때 실수를 정리하는 데 유용합니다.

이 모든 것들은 32 비트와 64 비트 프로그램간에 메모리를 공유하는 것에 대해 확신하지 못했습니다. 유닉스 API를 사용하는 것이 좋으며, 실패한다면 아마 할 수 없다. Boost는 구현시 사용됩니다.

+0

죄송합니다. 크로스 플랫폼 코드를 유지해야하기 때문에 원시 유닉스 공유 메모리 API를 사용할 수 없습니다. – MacGeek

+0

@ Rahul, 어떤 플랫폼을 타겟팅하고 있습니까? –

+0

WIN XP/VISTA/7 & MAC OS 10.6/7 – MacGeek