apr 공유 라이브러리 here을 사용하여 아파치 모듈 코드를 얻었습니다.apr_shm 라이브러리를 사용하는 구조체의 포인터에 대한 포인터
그리고 공유 데이터는 다음과 같이 등등 포인터에 대한 포인터를 가지고 몇 가지 필드를 추가하고, 구조체에 나는 수정 ..
typedef struct {
int a;
int b;
char *str;
double **dpp;
STRU1 **str;
} shm_data;
/* The per-server configuration */
typedef struct {
char *shmcounterfile;
char *shmcounterlockfile;
apr_global_mutex_t *mutex; /* the cross-thread/cross-process mutex */
apr_shm_t *data_shm; /* the APR shared segment object */
shm_data *data; /* the per-process address of the segment */
} shm_data_scfg_t;
...
/* parent httpd init code => ap_hook_post_config */
scfg = (shm_data_scfg_t*)ap_get_module_config(s->module_config, &shm_module);
apr_shm_create(&scfg->data_shm, sizeof(*scfg->data),
scfg->shmcounterfile, pconf);
/* The pointer to the shm_data structure is only valid
* in the current process, since in another process it may
* not be mapped in the same address-space. This is especially
* likely on Windows or when accessing the segment from an
* external process. */
scfg->data = (shm_data*)apr_shm_baseaddr_get(scfg->data_shm);
/* Clear all the data in the structure. */
memset(scfg->data, 0, sizeof(*scfg->data));
scfg->data->a = 1;
scfg->data->b = 2;
scfg->data->str = "test";
scfg->data->dpp = (double**)malloc(sizeof(double*) * 10);
for (int i = 0; i < 10; i++) {
scfg->data->dpp[i] = (double*)malloc(sizeof(double) * 10);
for (int l = 0; l < 10; l++) {
scfg->data->dpp[i][l] = l;
}
}
...
그리고 그것을 잘 작동합니다. 자식 프로세스는 'dpp'또는 'str'의 값에 액세스 할 수 있습니다.
내가 아는 한 malloc'd는 다른 프로세스에서 읽을 수없는 프로세스 (부모 httpd)에 개인 메모리를 할당했습니다. (어린이 httpd)
어떻게 작동합니까? 어떤 도움을 주셔서 감사합니다.
"* ... 메모리는 서로 액세스 할 수 없습니다. *"무엇을 표현 하시겠습니까? – alk
또한 C 또는 C++에 대한 내용입니까? C가 네가 APR을 사용하고있는 것 같아, 그렇지? – alk
즉, 포인터의 값은 현재 프로세스에서만 유효합니다. 죄송합니다. 나는 영어로 가난하다. 이것은 gpr에서 apr을 사용하여 컴파일됩니다. – cheoree