Re: [PATCH] Portable flexible arrays instead of r12255

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Wed, 17 Oct 2012 23:58:09 -0600

On 10/17/2012 10:01 PM, Yu-Teh Shen wrote:

> The class FlexibleArray will not delete the *items array, would it cause
> memory leak?

The class is using placement-new operator to initialize the array.
Placement-new does not allocate memory. Since the class does not
allocate memory for the array, it should not delete memory used by the
array. The caller is responsible for doing both.

> And what the shared memory coming from if you don't have copy
> constructor or something else.

IIRC, the [shared] memory for the array (and the object that includes
the array as a member) is allocated by various Owner::New() calls in
ipc/mem/Pointer.h when various shared structures such as StoreMap or
disker queues are created.

This is complicated, ugly code (but it is the best we could come up
with). We needed code to allocate and refcount shared memory segments,
code to initialize the allocated memory, and code to use shared memory
(in other processes or at other times) without initialization by using
type casts (with some safety checks).

HTH,

Alex.

> On Tue, Oct 16, 2012 at 3:56 AM, Alex Rousskov wrote:
>
> Hello,
>
> Trunk r12255 made Clang compiler happy by removing flexible nonPod[]
> arrays. Unfortunately, it also moved shared memory items into local
> memory (in some cases uninitialized). See the "[PATCH] Improve CLANG
> support" thread.
>
> The attached patch provides a Clang-friendly flexible array replacement
> while keeping items in the shared memory (and using placement-new
> initialization). The code may have become even less readable, but
> hopefully more portable.
>
> The changes passed build farm tests (except a couple of nodes with
> Jenkins-related build problems unrelated to the code).
>
>
> Thank you,
>
> Alex.
>
>
Received on Thu Oct 18 2012 - 05:58:13 MDT

This archive was generated by hypermail 2.2.0 : Thu Oct 18 2012 - 12:00:06 MDT