How to create an effective image buffer in C ++?

I am trying to create a data buffer, or rather, an image buffer that will be shared among several modules. These modules are read only from the buffer and do not communicate with each other at all. My difficulty:

1. Big data size:

more than 10 M per image, which means that copying this data around different streams is undesirable.

2. I do not want the memory to grow:

as new data continuously arrives (in real time), very old data should be deleted when all modules have finished using it.

However, to make things even more complex, those modules that consume data are at different rates: some of them are faster / slower, some require more data (several images), to get the result, some need less (only one image)

I was thinking about using shared_ptr to solve the first problem: create a boost queue shared_ptr (s), each shared_ptr () points to an image (char array). Then pass a subset of these pointers to another module.

I am completely new to this smart pointer field. What would be a good solution to this problem?

Thanks.

+3
source share
6 answers

, shared_ptr , . .

, - .
, .
? , , ? ?

:
, / , . a shared_ptr/shared_array , .
, .

+2

A Boost , . , .

, boost:: shared_array shared_ptr, .

shared_array . ( ++ new[].) , shared_array reset.

+3

, , :

  • shared_array<char>,
  • : , .

, , shared_array<char>. .

, Consumer/Producer, , , () , , (, ) .

: 3 , - , - , 3 3.

=> receiving image 1
module a: ['1'] -> processing (none)
module b: ['1'] -> processing (none)
module c: ['1'] -> processing (none)

=> modules a, b starts treatment of '1'
module a: [] -> processing '1'
module b: [] -> processing '1'
module c: ['1'] -> processing (none)

=> receiving image 2
module a: ['2'] -> processing '1'
module b: ['2'] -> processing '1'
module c: ['2', '1'] -> processing (none)

=> module a finishes treatment of '1', starts treatment of '2'
module a: [] -> processing '2'
module b: ['2'] -> processing '1'
module c: ['2', '1'] -> processing (none)

=> receiving image 3
module a: ['3'] -> processing '2'
module b: ['3', '2'] -> processing '1'
module c: ['3', '2', '1'] -> processing (none)

=> module c starts treatment of '1', '2' and '3'
module a: ['3'] -> processing '2'
module b: ['3', '2'] -> processing '1'
module c: [] -> processing '1', '2' and '3'

=> module a finishes treatment of '2', starts treatment of '3'
=> module b finishes treatment of '1', starts treatment of '2'
=> module c finishes treatment of '1' and '2', keeps '3' for future batch
module a: [] -> processing '3'
module b: ['3'] -> processing '2'
module c: [] -> processing '3' (waiting)

--> at this point '1' is deleted from memory

"", () "".

, , , ( ), ...

+1

1. :

, .

2. , .

, shared_ptr(). / shared_ptr(), , , shared_ptr(). shared_ptr() , , , , .

0

, posix . , .

Btw: posix? mmap Linux ..

0

boost:: shared_array ( ). boost:: circle_buffer .

boost::circular_buffer< const boost::shared_array<char> > input_queue_;

, .

0

Source: https://habr.com/ru/post/1720640/


All Articles