Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

aliusam

@aliusam
About
Posts
7
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • heap corruption after call to select() [modified]
    A aliusam

    hi all i am writing a thread per client server, well its not really a server, but it destributes jobs and calculations to other connected PCs. i have been having this error Free Heap block 00DB3D28 modified at 00DB3D78 after it was freed Windows has triggered a breakpoint now i traced the corruption of the heap by using _heapchk() and i found that the heap is being corrupted after a call to select() with fd_set containing one socket to check it for readability, the call to _heapchk() befor the select() returns _HEAPOK and after the select() it returns _HEAPBADNODE. the call to select() is inside the client specific thread, the first client that connects has no problem at all, when a second client connects the select() works fine untill there are nothing to read from the socket, call select() and returns zero then the heap corrupts, how to solve such a problem where the code is not under my control???? i am using VC++ 2005 and win xp. another thing, the thread proc is part of an object, that is creating a thread by calling a static function passing pointer to an object and inside the static function call a member function of object, dose that effect the heap in any way harmful??? i used to do it all the time with no problems. here is the thread code:

    thread(void* pParam)
    {
    int bytesSent,bytesToBeSent;
    int bytesRecv = SOCKET_ERROR;
    char sendbuf[4096] = "";
    char recvbuf[4096] = "";
    char tempbuf[4096] = "";

    // tell client to send its status
    short\* aa = (short\*) &sendbuf\[0\];
    \*aa = PGA\_CMD\_SENDSTATE;
    bytesToBeSent = 2;
    bytesSent = send( socket, sendbuf, bytesToBeSent, 0 );
    aa=NULL;
    
    NotCritical = true;
    
    /////// loop
    int cmd,i,j,s,ret = 0;
    TIMEVAL t;
    t.tv\_sec=0;
    t.tv\_usec=5000;
    fd\_set fd;
    
    
    while( 1 )
    {
    	FD\_ZERO(&fd);
    	FD\_SET(socket,&fd);
    
    	int hs2 = \_heapchk();      // hs2 = \_HEAPOK
    
    	ret = select(0, &fd, NULL, NULL, &t);
    
    	hs2 = \_heapchk();         // hs2 = \_HEAPBADNODE
    
    	if ( ret > 0 )
    	{
    		s=0;
    		bytesRecv = recv( socket, recvbuf, 4096, 0);
    		if(bytesRecv == SOCKET\_ERROR)
    			goto ERR;
    		cmd = \*(short\*)recvbuf;
    		j=2;
    		switch(cmd)
    		{
    		//////////here we process recv data
    		}// end switch(cmd)
    
    	}
    	else	// if ( ret > 0 )
    	{
    		if( ret < 0)
    			goto ERR;
    	}
    
    
    }
    

    ERR:
    closesocket(socket);
    state |= CI_STATE_ERROR;
    isBad = true;
    return 0;
    }

    any ideas?????? if i comment out the line

    // ret = select(0, &amp;fd, NULL, NULL, &amp;t);
    
    C / C++ / MFC help c++ sysadmin debugging tutorial

  • i can't add a CArray member to a class !!! error c2248 !!!
    A aliusam

    hiiii thank you all for the help, now it is working really great. but let me make things clear so if someone had the same problem can see where the error, cause the message you get from the compiler is not even close from the problem. let say you have a class: class BB { public BB(); virtual ~BB(); CArray AA; // or even a CAtringArray BB &operator=(const BB &otherBB) // without this operator you cant add a CArray or CStringArray }

    Snorri wrote:

    Probably the class you declare the CArray in already has one? Or at least you are using '=' somewhere in your code for an instance of that class

    when i read that i new the problem, it is in my class, see no class has no operator'=' (that if you used it in the program), so if you dont define one, the compiler will, and it will do it by calling each member's '=' operator, and if the operator is not existed then it stops and gives an error, evry one knows that but the error explanation dont even mentions it, and when i searched i didnot find an answer, so one can be drifted away. thanks all again regards

    Ali Usam AlCherchefchi

    C / C++ / MFC help csharp visual-studio question

  • i can't add a CArray member to a class !!! error c2248 !!!
    A aliusam

    i tried but the same error, i also tried the initialization list but the same.

    Ali Usam AlCherchefchi

    C / C++ / MFC help csharp visual-studio question

  • i can't add a CArray member to a class !!! error c2248 !!!
    A aliusam

    you mean to drive a class from "TYPE" and overload the '=' operator?? the CString already have one, or you mean to drive from the CArray and overload the '='??? i think this will work but not necessary, if the code will use the '=' operator each time i add an item this will be a big performance problem as the array may be long, 1000 or 10000, not sure yet. now i think the problem is the class could not construct the array, but adding it in the constructor did not help!!!!

    Ali Usam AlCherchefchi

    C / C++ / MFC help csharp visual-studio question

  • i can't add a CArray member to a class !!! error c2248 !!!
    A aliusam

    hiii this is the header:

    #pragma once
    #include "ga_dna.h"
    #include "afxtempl.h"

    #define NoOf_cValues 20
    #define NoOf_rValues 51

    class GA_Individual
    {
    public:
    GA_Individual(void);
    public:
    virtual ~GA_Individual(void);
    public:
    GA_DNA dna1;
    .
    .
    .
    .
    .
    // constructors
    GA_Individual(GA_DNA* pDNA);

    static unsigned short c\[NoOf\_cValues\];
    static unsigned short r\[NoOf\_rValues\];
    

    public:
    // always call this function befor using the class to initialize it
    static bool initIndiv(void);

    CArray <CString> opamp;        //tried "	CArray <CString,CString&> opamp;
    

    " and the same
    };

    the .cpp is like:

    #include "StdAfx.h"
    #include "GA_Individual.h"
    //#define _CRT_RAND_S // required to use rand_s() // defined in the compiler comand line
    #include "stdlib.h"
    #include "windows.h"

    #include <tchar.h>
    #include <math.h>

    unsigned short GA_Individual::c[NoOf_cValues];
    unsigned short GA_Individual::r[NoOf_rValues];

    GA_Individual::GA_Individual(void)
    : Age(0)
    {
    CArray <CString> opamp(void); // i tried this line but it did not solve a thing
    }

    GA_Individual::~GA_Individual(void)
    {
    }

    GA_Individual::GA_Individual(GA_DNA* pDNA)
    {
    ......
    }

    bool GA_Individual::initIndiv(void)
    {
    ......
    }
    .
    ....... other function definitions here
    .

    i noticed a thing, if i make the array a ststic ( static CArray opamp; ) member the code compiles, i can use it as a static with few axtra lines, but i am thinking what if using it as static was not an option, one should be able to add any type to the class, right, even if it did not have the operator '=' ???

    Ali Usam AlCherchefchi

    C / C++ / MFC help csharp visual-studio question

  • i can't add a CArray member to a class !!! error c2248 !!!
    A aliusam

    :( thanks for the reply but that did not help i tried

    CArray<CString,CString&> AA;

    and

    CStringArray AA;

    same error in both cases, it is looking for the operator =, but i did not use the variable yet:confused:

    Ali Usam AlCherchefchi

    C / C++ / MFC help csharp visual-studio question

  • i can't add a CArray member to a class !!! error c2248 !!!
    A aliusam

    my program works fine, untill i tried to add some feature. i added a " CArray AA " to my class in the header file and the code no longer compiles, i did not refrence the variable yet and it gives me a function related error, here is the error: 1>D:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afxtempl.h(272) : error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' 1> D:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afx.h(554) : see declaration of 'CObject::operator =' 1> D:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afx.h(524) : see declaration of 'CObject' 1> This diagnostic occurred in the compiler generated function 'CArray &CArray::operator =(const CArray & )' 1> with 1> [ 1> TYPE=CString 1> ] if i comment out the line " CArray AA " the code compiles with no problem, i am using CArray in other parts in the program but not as members, they are created inside functions and they work fine why is the error and what can i do about it?? i want to read a list from a text file that a user saves Ali Usam AlCherchefchi modified on Saturday, December 6, 2008 1:16 PM

    C / C++ / MFC help csharp visual-studio question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups