Created
November 16, 2012 04:30
Revisions
-
hank revised this gist
Nov 16, 2012 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,6 @@ #include <cstdlib> #include <sstream> int main(int argc, char** argv) { namespace ip = boost::interprocess; -
hank created this gist
Nov 16, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ CFLAGS=-O3 -Wall TARGETS=example1_server example1_client all: $(TARGETS) example1_server: example1_server.cpp $(CXX) $(CFLAGS) -o $@ $< example1_client: example1_client.cpp $(CXX) $(CFLAGS) -o $@ $< clean: rm -f $(TARGETS) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ hank@shelob ~/repos/life/code/cpp/boost/interproc $ ./example1_server & [1] 55037 hank@shelob ~/repos/life/code/cpp/boost/interproc $ Handle is 192 hank@shelob ~/repos/life/code/cpp/boost/interproc $ ./example1_client 192 Message: Manatees! This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ #include <boost/interprocess/managed_shared_memory.hpp> #include <cstdlib> #include <sstream> #define ALLOC_BYTES 1024 int main(int argc, char** argv) { namespace ip = boost::interprocess; ip::managed_shared_memory segment(ip::open_only, "Erik"); ip::managed_shared_memory::handle_t handle = 0; std::stringstream s; s << argv[1]; s >> handle; void* message = segment.get_address_from_handle(handle); printf("Message: %s\n", (char*)message); segment.deallocate(message); return EXIT_SUCCESS; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #include <boost/interprocess/managed_shared_memory.hpp> #include <cstdlib> #include <sstream> #define ALLOC_BYTES 1024 int main() { namespace ip = boost::interprocess; struct shm_remove { shm_remove() { ip::shared_memory_object::remove("Erik"); } ~shm_remove() { ip::shared_memory_object::remove("Erik"); } } remover; ip::managed_shared_memory segment(ip::create_only, "Erik", 32768); std::size_t free_memory = segment.get_free_memory(); void * shptr = segment.allocate(ALLOC_BYTES); if(free_memory <= segment.get_free_memory()) { return EXIT_FAILURE; } strcpy((char*)shptr, "Manatees!"); ip::managed_shared_memory::handle_t handle = segment.get_handle_from_address(shptr); std::cout << "Handle is " << handle << std::endl; pause(); return EXIT_SUCCESS; }