Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of database memory sharing?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the implementation principle of database memory sharing". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "what is the implementation principle of database memory sharing" together.

Shared memory is a way of communicating between processes. PostgreSQL uses shared memory to cache data and various data structures.

The following is a demo code, logic is very simple, self-reference code comments.

/* Request a shared memory, the parent process writes a string of characters, the child process reads. */# include #include //1k shared memory #define SHM_SIZE 1024#define SHM_ID 10086int main(){ //shared memory id, child process id int shmid, pid; //shared memory pointer char *ptr = NULL; //request shared memory shmid = shmget((key_t)SHM_ID, SHM_SIZE, IPC_CREAT | 0600); //Map shared memory to process address space ptr = (char *)shmat(shmid, 0, 0); printf("Attach pointer addr is %p \n", ptr); ptr = "This is shared memory! "; printf("The String of Parent Process is : %s \n", ptr); if((pid = fork()) == -1) { perror("fork process error! "); exit(0); } else if(! pid) { printf("Child Process PID is : %d,String is %s \n", pid,ptr); exit(0); }else{ sleep(1); //Unmap shmdt(ptr); //Delete shared memory shmctl(shmid, IPC_RMID, 0); } return 0;}

operation output

[pg12@localhost ipc]$ gcc -std=c11 -o fork fork.c In file included from fork.c:7:0:/usr/include/sys/ipc.h:24:3: warning: #warning "Files using this header must be compiled with _SVID_SOURCE or _XOPEN_SOURCE" [-Wcpp] # warning "Files using this header must be compiled with _SVID_SOURCE or _XOPEN_SOURCE" ^[pg12@localhost ipc]$ ./ fork Attach pointer addr is 0x7f61ffb6b000 The String of Parent Process is : This is shared memory! Child Process PID is : 0,String is This is shared memory! [pg12@localhost ipc]$Thank you for reading, the above is the "database memory sharing implementation principle is what" content, after the study of this article, I believe that everyone on the database memory sharing implementation principle is what this problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report