Click here to Skip to main content
16,011,120 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralNon ascii character in CSV file Pin
Alberto Bar-Noy13-Jan-03 22:30
Alberto Bar-Noy13-Jan-03 22:30 
GeneralRe: Non ascii character in CSV file Pin
Ted Ferenc13-Jan-03 22:43
Ted Ferenc13-Jan-03 22:43 
Generalnew&delete, malloc&free Pin
raner13-Jan-03 22:26
raner13-Jan-03 22:26 
GeneralRe: new&delete, malloc&free Pin
jhwurmbach13-Jan-03 22:46
jhwurmbach13-Jan-03 22:46 
GeneralRe: new&delete, malloc&free Pin
raner14-Jan-03 0:19
raner14-Jan-03 0:19 
GeneralRe: new&delete, malloc&free Pin
jhwurmbach14-Jan-03 1:08
jhwurmbach14-Jan-03 1:08 
GeneralThks jhwurmbach & AlexO Pin
raner14-Jan-03 20:56
raner14-Jan-03 20:56 
GeneralRe: Thks jhwurmbach & AlexO Pin
jhwurmbach14-Jan-03 22:59
jhwurmbach14-Jan-03 22:59 
raner wrote:
But can i confirm that the following statements should be fine?
[..example deleted..]

No! You have 100 'new int' instructions (in the loop), but only one delete (after the loop). You are leaking 99 ints.

This one works:
#include < iostream >
#define num 100
int main(int argc, char* argv[])
{
    typedef int* intPtr;
    //allocate memory for an array of int*, size of array is num
    intPtr* pI = new intPtr[num];

    //allocate the numbers
    for(int i = 0; i < num; ++i)
    {
        pI[i] = new int;
        *pI[i] = i*i;
    }

    //use the numbers
    for( i = 0; i < num; ++i)
        std::cout << "i: " << i << "  i quadrat: " << *pI[i] << std::endl;
    
    //delete the content of the arry of pointers
    //that is, delete the numbers
    for(i = 0; i < num; ++i)
    {
        delete pI[i];
    }
    //delete the array of pointers to numbers
    delete[] pI; 	

    return 0;
}



My opinions may have changed, but not the fact that I am right.
GeneralRe: Thks jhwurmbach & AlexO Pin
raner15-Jan-03 3:54
raner15-Jan-03 3:54 
GeneralRe: new&delete, malloc&free Pin
AlexO14-Jan-03 4:20
AlexO14-Jan-03 4:20 
GeneralWord Automation Pin
Exceter13-Jan-03 18:56
Exceter13-Jan-03 18:56 
GeneralRe: Word Automation Pin
Anonymous13-Jan-03 20:40
Anonymous13-Jan-03 20:40 
GeneralMAC based Firewall Pin
summo13-Jan-03 18:11
summo13-Jan-03 18:11 
GeneralRe: MAC based Firewall Pin
Dana Epp15-Jan-03 9:02
Dana Epp15-Jan-03 9:02 
Generalproblem in debugging VC 6 code in windows xp Pin
r i s h a b h s13-Jan-03 16:45
r i s h a b h s13-Jan-03 16:45 
General*.pck file Pin
:_Rocket_:13-Jan-03 16:04
:_Rocket_:13-Jan-03 16:04 
GeneralRe: *.pck file Pin
Taka Muraoka13-Jan-03 17:38
Taka Muraoka13-Jan-03 17:38 
GeneralRe: *.pck file Pin
Ted Ferenc13-Jan-03 22:54
Ted Ferenc13-Jan-03 22:54 
Generalmodeless dialog(rather long story), I appreciate Pin
Anonymous13-Jan-03 15:29
Anonymous13-Jan-03 15:29 
GeneralRe: modeless dialog(rather long story), I appreciate Pin
Joaquín M López Muñoz13-Jan-03 20:58
Joaquín M López Muñoz13-Jan-03 20:58 
GeneralRe: modeless dialog(rather long story), I appreciate Pin
Hans Ruck13-Jan-03 22:02
Hans Ruck13-Jan-03 22:02 
GeneralRe: modeless dialog(rather long story), I appreciate Pin
Anonymous14-Jan-03 3:53
Anonymous14-Jan-03 3:53 
GeneralRe: modeless dialog(rather long story), I appreciate Pin
Hans Ruck14-Jan-03 5:14
Hans Ruck14-Jan-03 5:14 
GeneralRe: modeless dialog(rather long story), I appreciate Pin
Anonymous14-Jan-03 5:25
Anonymous14-Jan-03 5:25 
GeneralRe: modeless dialog(rather long story), I appreciate Pin
Hans Ruck14-Jan-03 5:44
Hans Ruck14-Jan-03 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.