开发者

Memory fragmentation @ boost::asio?

开发者 https://www.devze.com 2023-01-01 09:40 出处:网络
I\'m pretty much stuck with a question I never got an answer for, a question which addresses an extremely important issue; memory fragmentation at boost::asio.

I'm pretty much stuck with a question I never got an answer for, a question which addresses an extremely important issue; memory fragmentation at boost::asio.

Found nothing at the documentation nor here at SO.

The async functions at boost::asio, for example async_write() & async_read_some() always allocate something. (in my case it's 144 & 96 bytes respectively, in VC9 Debug build).

How do I know about it?

I connect a client to the "echo server" example provided with this library.

I put a breakpoint at "new.cpp" at the code of "operator new(size_t size)".

Then I send "123". Breakpoint is hit!

Now using the stack trace I can clearly see that the root to the "new" call is coming from the async_write() & async_read_some() calls I make in the function handlers.

So memory fragmentation will com开发者_如何转开发e sooner or later, thus I can't use ASIO, and I wish I could!

I want to note that I understand that an async operation requires, at least at IOCP, an allocated structure to be used during the operation, until completion (when handler is called).

For example with IOCP you must have an OVERLAPPED structure for each operation (read/write).

I suspect this is the reason that I have the above small allocations, who worries me about memory fragmentation.

How do I pool these strctures then? Platform-independent of course.

Any idea? Any helpful code example? I'm sure some of you already solved this issue.


Sounds like you need to use the asio custom memory allocation capabilities, have you read the documentation? There's also a fairly straightforward example.

0

精彩评论

暂无评论...
验证码 换一张
取 消