I use stupid thread titles.

This is a discussion on I use stupid thread titles. within the C++ Programming forums, part of the General Programming Boards category; Please tell my errors whatever is....

  1. #16
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Please tell my errors whatever is.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #17
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by CornedBee
    On a proper compiler, new throws an exception when unable to allocate space.
    You might use a "proper compiler".
    Kurt

  3. #18
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Use (nothrow). Sometimes it doesn't work.
    Once I included new.h and tried set_new_handler(), but it generated error. I think it was because of my old headers.
    Last edited by siavoshkc; 01-26-2006 at 01:23 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #19
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> Sometimes it doesn't work.

    >> Once I included new.h and tried set_new_handler(), but it generated error.

    Vague. Really really really vague.

  5. #20
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Use nothrow to force new not to generate exception.(Although it wont work with old headers). Another way to handle errors is to use set_new_handler() from new or new.h
    Headers.
    Code with new.h compiles in my PC but generates an assertion fail and doesn't work.
    Code:
    void errh(void);
    const int arlmt=10000;
    long double *v[arlmt];
    const int ind =10000000;
    
    main()
    {	
    	set_new_handler(errh);
    	int nfaloc=0;
    	int sum=0;
    	
    	for(int s=1;s<arlmt;s++)
    	{
    	
    		v[s]=new long double[ind/s];
    		if(v[s]) 
    		{
    			
    			for(int i=0;i<ind/s;i++) *(v[s]+i)=(long double)i;
    			
    			sum+=(ind/s);
    			int fortest=0;
    			cout<<  ((ind/s)*8)/(1024) 
    				<<" KBs at "<< v[s] 
    				<<"  Test: "; 
    			for(i=0;i<ind/s;i++) {
    				if(*(v[s]+i)!=(long double)i) {fortest=1;break;}
    				
    			}
    			if(fortest==1) cout<<"Failed. ";
    			else cout<<"OK. ";
    			cout << "Total: "<<(sum*8)/(1024*1024)<<" MBs allocated and tested."<<endl;
    		}
    		else
    			nfaloc++;
    
    	}
    	
    	cout<<nfaloc<<" Number of allocations failed!"<<endl;
    	cout<< "Press a key..."  <<endl;
    	getch();
    	return 0;
    }
    
    
    void errh(void)
    {
    	cout<<"ERR allocating!"<<endl;
    }
    Clear?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 08:27 AM
  2. Need some help with truncation of thread titles
    By major_small in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-24-2006, 11:00 AM
  3. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 05:34 AM
  4. Thread confusion
    By pyrolink in forum C Programming
    Replies: 0
    Last Post: 01-29-2006, 09:42 PM
  5. Thread inside a thread ?
    By lsme in forum Linux Programming
    Replies: 3
    Last Post: 12-08-2004, 11:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21