> -----Original Message-----
> From: boost-users-bounces@lists.boost.org [mailto:boost-users-
> bounces@lists.boost.org] On Behalf Of Beman Dawes
> Sent: Thursday, December 16, 2004 4:19 PM
> To: boost-users@lists.boost.org; boost-users@lists.boost.org
> Subject: Re: [Boost-users] boost and memory allocations (signals and
> others)
>
> At 09:17 AM 12/15/2004, Caleb Epstein wrote:
> >On Mon, 13 Dec 2004 09:01:01 -0800, Frank Maddin
> <frankmad@microsoft.com>
>
> >wrote:
> >
> >> We've been thinking about using certain boost functionality on a
> project.
> >
> >> We were trying to keep the number of allocations down.
> >
> >See the attached test program which makes the Hello class "noisy" and
> >runs two different versions of your signals test. One uses object
> >copy semantics and the other uses reference semantics. Compare the
> >output:
> >
> >copy test:
> >Hello::Hello () @ 0xbfffb950
> >Hello::Hello (const ref) @ 0xbfffb8c0
> >Hello::Hello (const ref) @ 0xbfffb870
> >Hello::Hello (const ref) @ 0xbfffb830
> >Hello::Hello (const ref) @ 0xbfffb7e0
> >Hello::Hello (const ref) @ 0x8050fb0
> >Hello::~Hello @ 0xbfffb7e0
> >Hello::~Hello @ 0xbfffb830
> >Hello::~Hello @ 0xbfffb870
> >Hello::~Hello @ 0xbfffb8c0
> >Hello::Hello (const ref) @ 0x8050fc0
> >Hello::Hello (const ref) @ 0x8050fc8
> >Hello::Hello (const ref) @ 0x8050fd0
> >Hello::~Hello @ 0x8050fc8
> >Hello::~Hello @ 0x8050fc0
> >Hello::~Hello @ 0x8050fb0
> >i = 1968
> >Hello::~Hello @ 0x8050fd0
> >Hello::~Hello @ 0xbfffb950
> >
> >ref test:
> >Hello::Hello () @ 0xbfffb950
> >i = 1968
> >Hello::~Hello @ 0xbfffb950
>
> Wow! That is a pretty substantial difference.
>
> Seems like the signals docs should make a point of explaining the
> efficiency gained by using ref. Or maybe they do, but I didn't find
> anything in several minutes of poking around the docs. There is no table
> of
> contents entry like "Efficiency considerations" or similar.
>
> --Beman
>
> _______________________________________________
> Boost-users mailing list
> Boost-users@lists.boost.org
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks, that did indeed remove some churn. As Mr. Dawes pointed out, it would be nice to have that info in the docs somewhere.
Overall though, I’m not sure that the allocations I’m seeing are acceptable for my application. Ideally, I’d like 1 allocation on connect and 0 allocations on signal send. We will be using an optimized small block allocator, but we still want to reduce memory operations as much as possible. Is there any suggestion to reduce this?
I ran my own test putting in _CrtSetAllocHook(MyAllocHook), just copied from msdn. Below are the results (cleaned up a bit for just alloc hook calls).
I haven’t really looked at memory pools too closely. Would they be useful in any sort of situation with signals?
From the pool docs:
>Pools are generally used when there is a lot of allocation and de-allocation of small objects. Another common usage
>is the situation above, where many objects may be dropped out of memory.
Thanks,
Frank
ref test
before declaration:
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 93)
Memory operation in (null), line 0: allocating a 40-byte 'Normal' block (# 95)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 96)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 97)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 3240f8
Memory operation in (null), line 0: allocating a 40-byte 'Normal' block (# 98)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 99)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 321688
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 100)
after declaration:
before connect:
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 101)
Memory operation in (null), line 0: allocating a 20-byte 'Normal' block (# 102)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 103)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 104)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 105)
Memory operation in (null), line 0: allocating a 20-byte 'Normal' block (# 106)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 107)
Memory operation in (null), line 0: allocating a 4-byte 'Normal' block (# 108)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 109)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 110)
Memory operation in (null), line 0: allocating a 40-byte 'Normal' block (# 111)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 112)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0)
at 3244e0Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0)
at 324490Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0)
at 324340Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0)
at 321688Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0)
at 324290Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0)
at 3242e8
after connect:
before sig send:
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 113)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 114)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 321688
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 324490
after sig send:
copy test:
before declaration:
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 67)
Memory operation in (null), line 0: allocating a 40-byte 'Normal' block (# 69)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 70)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 71)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 3240f8
Memory operation in (null), line 0: allocating a 40-byte 'Normal' block (# 72)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 73)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 321688
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 74)
after declaration:
before connect:
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 75)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 76)
Memory operation in (null), line 0: allocating a 20-byte 'Normal' block (# 77)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 78)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 79)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 80)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 81)
Memory operation in (null), line 0: allocating a 20-byte 'Normal' block (# 82)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 83)
Memory operation in (null), line 0: allocating a 4-byte 'Normal' block (# 84)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 85)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 86)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 87)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 88)
Memory operation in (null), line 0: allocating a 40-byte 'Normal' block (# 89)
Memory operation in (null), line 0: allocating a 16-byte 'Normal' block (# 90)
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 91)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 3245f0
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 3245a0
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 324560
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 324510
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 32439
0Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 324340
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 3240f8
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 321688
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 324290
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 3242e8
after connect:
before sig send:
Memory operation in (null), line 0: allocating a 1-byte 'Normal' block (# 92)
Memory operation in (null), line 0: allocating a 24-byte 'Normal' block (# 93)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0)
Memory operation in (null), line 0: freeing a 0-byte 'Normal' block (# 0) at 324510
after sig send: