POV-Ray : Newsgroups : povray.off-topic : Smart little programming tricks, where to find ? : Re: Smart little programming tricks, where to find ? Server Time
11 Oct 2024 01:24:33 EDT (-0400)
  Re: Smart little programming tricks, where to find ?  
From: Fredrik Eriksson
Date: 19 Mar 2008 19:10:55
Message: <op.t8af4hfr7bxctx@e6600>
On Thu, 20 Mar 2008 00:52:55 +0100, stbenge <stb### [at] hotmailcom> wrote:

> Say I wrote
>
> int** foo = NULL;
> int nx = 22, ny = 17;
>
> void matrixfunc(){
>   foo = new int*[nx];
>
>   for (int x = 0; x < nx; x++)
>    foo[x] = new int[ny];
> }

Much better to use std::vector instead. Avoid raw pointers like the  

plague; it will save you many headaches.



> and called matrixfunc();, but before I could delete it
>
> for (int x = 0; x < nx; x++)
>   delete[] foo[x];
>
>   delete[] foo;
>   foo = NULL;
>
> the code crashed. Do I have a memory leak?

If by "crash" you mean unexpected program termination, then not really  

(not because of the crash anyway). Any modern desktop OS will reclaim th
e  

resources held by a program when said program terminates.



-- 

FE


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.