Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: [Win32] pthreads and memory allocation

by syphilis (Chancellor)
on Nov 22, 2011 at 07:22 UTC ( #939383=note: print w/replies, xml ) Need Help??

in reply to Re: [Win32] pthreads and memory allocation
in thread [Win32] pthreads and memory allocation

It's just a demo to illustrate that malloc() causes a crash on Win32 (but not elsewhere, afaik).
Perhaps I should have declared char * useless_and_pointless; instead of char * s;.

Now a malloc() call should have a conditional statement to see that it actually worked

Yes, if you're wanting to make use of the memory that you've requested be allocated, I think that's a good idea. For the purposes of this demo, however, I don't really care whether the malloc succeeds or fails - I just want it to not cause a crash.
(Besides, on Win32, I'm not even going to see the result of that "conditional statement" because it never gets executed - due to afore-mentioned crash.)

Similarly, any memory leak is of no concern to me wrt this particular exercise.


Replies are listed 'Best First'.
Re^3: [Win32] pthreads and memory allocation
by Marshall (Monsignor) on Nov 22, 2011 at 08:28 UTC
    Perhaps I should have declared char * useless_and_pointless; instead of char * s;.

    Yes, I figure that would be correct and I figure that we understand each other.

    The basic issue is: "s = (char*) malloc(100);". "s" is cast as a pointer to a memory address. "s" is guaranteed to point to at least 100 bytes (consecutive).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939383]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2016-10-22 02:02 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.