Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C++ Libraries / June 2006

Tip: Looking for answers? Try searching our database.

malloc vc++ express

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
voguy - 15 Jun 2006 18:23 GMT
Hi,

I don't know if this is the right place to report this behaviour with malloc
using the C RTL no managed code on a vista platform with all optimization
off. See below the message i sent to another newsgroup already.

Also if i do the test setting a breakpoint on the return statement of main()
and run the test with pressing F5 for release there is no problem. When i
delete the breakpoint and let the test run I get a heap node error.

code snippet in main:

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned char * p[100];

    for (int i=0;i<100;i++)
    {
        p[i] = (unsigned char *)malloc(10);
    }

    heapdump();

    for (int i=0;i<100;i++)
    {
       free(p[i]);
    }

    heapdump();
return 0; // here is the breakpoint
}

No more no less.

The question is in fact is it safe to use VC++ express edition after a
windows vista upgrade or are there any important notes i must know to work
malloc/free?

/****************** from my other discussion *************/

Extra platform information for the test:

OS = Vista beta2 (ugrade on XP home)

and VC express was already installed before the vista upgrade.

I did the same test on VS2003 edition on W2000 OS and there was no problem
at all !

Do I have to reinstall the VC express on Vista perhaps ?

"voguy" wrote:

> Hi,
>
> I recently needed to study a bit the malloc/free functions for a project out
> of VC. I tested a few things out in VC express with a simple console program
> to have a beter in-depth view of the working. I found something strange when
> I allocated small amounts of bytes :
>
> If I do:
>
> malloc(10) let say for 100 times and run this functions afterwards
>
> void heapdump( void )
> {
>    _HEAPINFO hinfo;
>    int heapstatus;
>    hinfo._pentry = NULL;
>    while( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK )
>    { printf( "%6s block at %Fp of size %4.4X\n",
>         ( hinfo._useflag == _USEDENTRY ? "USED" : "FREE" ),
>           hinfo._pentry, hinfo._size );
>    }
>
>    switch( heapstatus )
>    {
>    case _HEAPEMPTY:
>       printf( "OK - empty heap\n" );
>       break;
>    case _HEAPEND:
>       printf( "OK - end of heap\n" );
>       break;
>    case _HEAPBADPTR:
>       printf( "ERROR - bad pointer to heap\n" );
>       break;
>    case _HEAPBADBEGIN:
>       printf( "ERROR - bad start of heap\n" );
>       break;
>    case _HEAPBADNODE:
>       printf( "ERROR - bad node in heap\n" );
>       break;
>    }
> }
>
> I get a "bad node in heap" ! If I do the same with fe
> malloc(1024) for 100 times the _heapwalk functions give no error and return
> with
> "OK - end of heap"
>
> I jus used the C RTL in the project nothing special. In the MSDN
> documentation I can't find anything on a minimum bytes or allignment limit.
>
> Anyone can bring up a light in this simpel example but odd result ?
>
> Many thks
> Guy
William DePalo [MVP VC++] - 15 Jun 2006 18:47 GMT
> I don't know if this is the right place to report this behaviour with
> malloc

malloc is OK.

> int _tmain(int argc, _TCHAR* argv[])
> {
[quoted text clipped - 4 lines]
>       p[i] = (unsigned char *)malloc(10);
> }

You can't do that. You told the compiler that p is a pointer to an unbroken
string of 100 characters. Then you assign that pointer to a string of 10
characters. That's a no-no.

Regards,
Will
voguy - 15 Jun 2006 19:33 GMT
hi,

You can't do that. You told the compiler that p is a pointer to an unbroken
> string of 100 characters.

I think you're wrong here. I declared a pointer array of 100 pointers no ?
Otherwise it is

unsigned char p[100]; // whitout the * !

> > I don't know if this is the right place to report this behaviour with
> > malloc
[quoted text clipped - 16 lines]
> Regards,
> Will
William DePalo [MVP VC++] - 15 Jun 2006 20:28 GMT
> I think you're wrong here.

Yes, I am. My humble apology.

I don't have the express edition installed here. I did try your snippet. It
ran to completion without asserting. Sorry, but I don't know what to say
about your problem.

Regards,
Will

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.