kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #07238
Re: operator new in board.cpp
On 12/05/2011 08:02 AM, Wayne Stambaugh wrote:
> On 12/5/2011 12:30 AM, Dick Hollenbeck wrote:
>> Wayne,
>>
>> I think the lines involving operator new() may blow up at runtime when the corresponding
>> delete [] is called.
> Dick,
>
> I'm not using
>
> delete[] foo; // This is not the same as delete foo[nn];
>
> where the contents of foo are allocated using
>
> foo = new();
>
> I'm using
>
> delete foo[nn]; // This is the same as tmp* = foo[nn]; delete tmp;
>
> where the contents of the array of foo pointers is assigned using
>
> foo[nn] = new( sizeof(foo) );
>
> In the case of m_BoardSide it is defined in the board class as
>
> MATRIX_CELL* m_BoardSide[MAX_SIDES_COUNT];
>
> so I'm just filling the array of pointers with the new() operator so delete()
> should work properly.
>
>> Have you tested this code?
> I ran the auto router and didn't it segfault and it generated the same results
> as the old code so it appears to be correct.
>
> Wayne
Ok. A related concern on this line:
/* allocate Board & initialize everything to empty */
m_BoardSide[kk] = (MATRIX_CELL*) operator new( ii * sizeof(MATRIX_CELL) );
My understanding is that the old code also did not run the constructor MATRIX_CELL on each
element within the range [0] < [ii-1].
But that the Mzalloc() simply zeroed out the memory before returning it?
I'm wondering if your comment is now accurate, since we:
a) do not run the constructors, and
b) do not zero out the memory.
Thanks,
Dick
Follow ups
References