I have encountered several problems while testing your shared-memory allocator.
Would you give me some hints or answers?
1. char error
The sample code in main.cc under /src dir runs well. However, when I modified the OBJECT type from int to char, it doesn't work.. The modified code is as follows:
However, after i removed the above 2 lines ends with "//NOTE", it fails again.
I guess the memory is not attached for the CONTAINER std::basic_string...
Well, it will be of much help if you show me a simple example just to demonstrate how to use a vector of string.
3. vector<vector>
I am planning to test this, but i guess the same situation as problem 2.
4. How can I put a single object in the shared-memory and access it in several processes? Do I have to use a vector or something ?
Thank you!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1. The first error messages appear to be warnings. The output seems to indicate that it found the 'A' and 'b' which were inserted. My guess is that you were testing the code and some old either semaphores or shared memory segments were left over causing a conflict which is being reported. In the bin directory, there is a shm_unlink program to delete old shared memory segments. Try running that and then running your code again to see if the error messages persist. Note, chunks will disappear in the next version, whenever I get to finish testing it.
2. Strings are little tricky as both the string and its character contents need to allocated in shared memory. The test directory has an example with Dilbert characters. See that code.
3. See the reply for 2.
4. If you just have a single object you might be better off just doing the raw shm_open system commands. you could use the allocator to allocate space for one object and then allow the second process to similarly attach to that object, but as an application it would be a bit convoluted. In the test code, I believe that there are examples doing this type of an excercise to verify the system.
Try reading and understanding the test code directory. Make sure these tests run on your platform.
Marc
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have just run the tests on my redhat linux. They've behaved as expected.
As I modified test/mult_proc.cc so that the vector in this case contained CHAR rather than INT and that the number of objects was reduced to 100, and run 'make' again, the result indicated that all chars were pushed in(Passed:100, Failed:0).
I have checked the test codes and src codes in the archive, and found that only test/map_with_string_index.cc contains an example that demostrates the usage of std::map with std::string. The tricky is found in the file include/pooled_allocator.h, Line 1411-1417.
My code follows the latter one. But without a declaration of a alloc_string_t type object before using the vector who contains it will cause unexpected termination. Thus, my connect and read program never success without such a declaration.
By the way, I am using version 1.07 of the allocator.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have encountered several problems while testing your shared-memory allocator.
Would you give me some hints or answers?
1. char error
The sample code in main.cc under /src dir runs well. However, when I modified the OBJECT type from int to char, it doesn't work.. The modified code is as follows:
typedef pooled_allocator::Pool_alloc<char,
key_val,
key_addr> my_vector_alloc_t;
typedef std::vector<char,my_vector_alloc_t> my_vector_t;
pooled_allocator::Multi_Process_Pool_alloc<my_vector_t,
char,
key_val,
key_container,
key_addr> temp_alloc;
my_vector_t* vec_ptr = temp_alloc.attach();
vec_ptr->push_back('A');
vec_ptr->push_back('b');
for (my_vector_t::iterator it = vec_ptr->begin();
it != vec_ptr->end(); it++) {
std::cout << *it << std::endl;
}
The output is as follows:
/home/allocator/src/pooled_allocator.h:1185 Pool<>::free() : valid chunk not found.
/home/allocator/src/pooled_allocator.h:1186 *p : a1 : num_of_elements : 1
Memory at address: 0x401294fa
Chunks value:0x401274fa
A
b
2. string
I tried to use a vector of strings in shared memory. The following code does work well:
typedef pooled_allocator::Pool_alloc<char,
key_val,
key_addr> char_allocator_t;
typedef std::basic_string<char,
std::char_traits<char>,
char_allocator_t> alloc_string_t;
typedef pooled_allocator::Pool_alloc<alloc_string_t,
key_val,
key_addr> my_vector_alloc_t;
typedef std::vector<alloc_string_t,
my_vector_alloc_t> my_vector_t;
pooled_allocator::Multi_Process_Pool_alloc<my_vector_t,
alloc_string_t,
key_val,
key_container,
key_addr> temp_alloc;
my_vector_t* vec_ptr = temp_alloc.attach();
alloc_string_t str(10u,'s'); // NOTE
vec_ptr->push_back(str); // NOTE
for (my_vector_t::iterator it = vec_ptr->begin();
it != vec_ptr->end(); it++) {
std::cout << *it << std::endl;
}
However, after i removed the above 2 lines ends with "//NOTE", it fails again.
I guess the memory is not attached for the CONTAINER std::basic_string...
Well, it will be of much help if you show me a simple example just to demonstrate how to use a vector of string.
3. vector<vector>
I am planning to test this, but i guess the same situation as problem 2.
4. How can I put a single object in the shared-memory and access it in several processes? Do I have to use a vector or something ?
Thank you!
1. The first error messages appear to be warnings. The output seems to indicate that it found the 'A' and 'b' which were inserted. My guess is that you were testing the code and some old either semaphores or shared memory segments were left over causing a conflict which is being reported. In the bin directory, there is a shm_unlink program to delete old shared memory segments. Try running that and then running your code again to see if the error messages persist. Note, chunks will disappear in the next version, whenever I get to finish testing it.
2. Strings are little tricky as both the string and its character contents need to allocated in shared memory. The test directory has an example with Dilbert characters. See that code.
3. See the reply for 2.
4. If you just have a single object you might be better off just doing the raw shm_open system commands. you could use the allocator to allocate space for one object and then allow the second process to similarly attach to that object, but as an application it would be a bit convoluted. In the test code, I believe that there are examples doing this type of an excercise to verify the system.
Try reading and understanding the test code directory. Make sure these tests run on your platform.
Marc
Thank you, Marc.
I have just run the tests on my redhat linux. They've behaved as expected.
As I modified test/mult_proc.cc so that the vector in this case contained CHAR rather than INT and that the number of objects was reduced to 100, and run 'make' again, the result indicated that all chars were pushed in(Passed:100, Failed:0).
However, messages like
/home/allocator/src/pooled_allocator.h:1185 Pool<>::free() : valid chunk not found.
/home/allocator/src/pooled_allocator.h:1186 *p : a1 : num_of_elements : 1
Memory at address: 0x401294fa
Chunks value:0x401274fa
were still printed.
I'm quite sure that the 'dirty' semophores or shared-memory segments were cleaned. So I guess CHAR is the prime criminal.
I have checked the test codes and src codes in the archive, and found that only test/map_with_string_index.cc contains an example that demostrates the usage of std::map with std::string. The tricky is found in the file include/pooled_allocator.h, Line 1411-1417.
My code follows the latter one. But without a declaration of a alloc_string_t type object before using the vector who contains it will cause unexpected termination. Thus, my connect and read program never success without such a declaration.
By the way, I am using version 1.07 of the allocator.