"define" and "malloc" more

Hi all,

In fact, I want to let my memory run out. And see what will happen. My 
system is windowsXp. Memory is 256M.I think my cdes will apply more memory 
than I have. Codes are below:

#include <stdlib.h>
#include<stdio.h>

#define MAX 1000000000

int main(void)
{
    long double  *temp = (long double*)malloc (MAX * sizeof(long double));
    long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));
    putchar(77);
    getchar();
    getchar();

    return 0;
}

But run these codes in my IDE, I do not say anything wrong in my system. So 
could anyone help? 


0
lyrachina (9)
8/17/2006 8:37:49 AM
comp.lang.c 30227 articles. 2 followers. spinoza1111 (3247) is leader. Post Follow

17 Replies
99 Views

Similar Articles

[PageSpeed] 41
every process will have 4GB virturl memroy.
and 2GB of it is user space in Windows ( other 2GB is for system )

P.S. send me an email if you have more queesion(s).

0
monnand (2)
8/17/2006 8:48:23 AM
Seems not only because of virtural memoral.
I checked my "windows task manager" while running the code. The usage of PF 
do not have any changes.
I expect an increased usage of PF.

"monnand" <monnand@gmail.com> 
??????:1155804503.247863.128500@i3g2000cwc.googlegroups.com...
> every process will have 4GB virturl memroy.
> and 2GB of it is user space in Windows ( other 2GB is for system )
>
> P.S. send me an email if you have more queesion(s).
> 


0
lyrachina (9)
8/17/2006 9:27:34 AM
Chen Shusheng schrieb:
> Hi all,
> 
> In fact, I want to let my memory run out. And see what will happen. My 
> system is windowsXp. Memory is 256M.I think my cdes will apply more memory 
> than I have. Codes are below:
> 
> #include <stdlib.h>
> #include<stdio.h>
> 
> #define MAX 1000000000
> 
> int main(void)
> {
>     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
>     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));

Take a texteditor and write 1000000000 times:

"I won't cast malloc's return value any more",

when done, write 1000000000 times:

"I will check malloc's return value for NULL every time".

>     putchar(77);
>     getchar();
>     getchar();
> 
>     return 0;
> }
> 
> But run these codes in my IDE, I do not say anything wrong in my system. So 
> could anyone help? 

I guess, malloc() returned NULL and there was no memory allocated at all.

-- 
Thomas
0
8/17/2006 9:56:00 AM
On 17 Aug 2006 01:48:23 -0700, "monnand" <monnand@gmail.com> wrote:

>every process will have 4GB virturl memroy.
>and 2GB of it is user space in Windows ( other 2GB is for system )

It's one thing to reply to an off-topic post. It's an entirely another
matter to reply to an off-topic post with false information.

http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx

>P.S. send me an email if you have more queesion(s).

I guarantee that you will never receive an email from me, because I'll
never have any "queesion(s)". I assume that your citation of "you"
applied to anyone in this newsgroup, just like I assumed that "virturl
memroy" referred to "virtual memory" and "queesion(s)" referred to
"question(s)".

Best regards
-- 
jay
0
jaysome1 (136)
8/17/2006 10:18:16 AM
Chen Shusheng wrote:
> Hi all,
>
> In fact, I want to let my memory run out. And see what will happen. My
> system is windowsXp. Memory is 256M.I think my cdes will apply more memory
> than I have. Codes are below:

> But run these codes in my IDE, I do not say anything wrong in my system. So
> could anyone help?

The system allocated the memory, but most of it sat on the disk as
virtual pages in the virtual swap file.

To actually exercise the memory, try setting each element of the array,
preferably at random.    Then leave for a 6-month vacation.  It may
take that long for the whole array to be populated.  Example:

for( i = 0; i < MAX; i++ ) {
       index = rand() * MAX;
      temp1[ index ] = 123.456; 
      temp2[ index ] = 456.789; 
 }

0
grg2 (355)
8/17/2006 10:22:48 AM
On 17 Aug 2006 03:22:48 -0700, "Ancient_Hacker" <grg2@comcast.net>
wrote:

>
>Chen Shusheng wrote:
>> Hi all,
>>
>> In fact, I want to let my memory run out. And see what will happen. My
>> system is windowsXp. Memory is 256M.I think my cdes will apply more memory
>> than I have. Codes are below:
>
>> But run these codes in my IDE, I do not say anything wrong in my system. So
>> could anyone help?
>
>The system allocated the memory, but most of it sat on the disk as
>virtual pages in the virtual swap file.
>
>To actually exercise the memory, try setting each element of the array,
>preferably at random.    Then leave for a 6-month vacation.  It may
>take that long for the whole array to be populated.  Example:
>
>for( i = 0; i < MAX; i++ ) {
>       index = rand() * MAX;
>      temp1[ index ] = 123.456; 
>      temp2[ index ] = 456.789; 
> }

That's not a very good example. According to the C Standard:

"The value of the RAND_MAX macro shall be at least 32767."

Three of your four lines of code could very well lead to undefined
behavior on a bunch of implementations.

Best regards
-- 
jay
0
jaysome1 (136)
8/17/2006 10:43:30 AM
Chen Shusheng wrote:

> Seems not only because of virtural memoral.

See below.



Brian
-- 
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>
0
defaultuserbr (3657)
8/17/2006 5:33:59 PM
"Chen Shusheng" <lyrachina@hotmail.tom> writes:
> In fact, I want to let my memory run out. And see what will happen. My 
> system is windowsXp. Memory is 256M.I think my cdes will apply more memory 
> than I have. Codes are below:
>
> #include <stdlib.h>
> #include<stdio.h>
>
> #define MAX 1000000000
>
> int main(void)
> {
>     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
>     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));
>     putchar(77);
>     getchar();
>     getchar();
>
>     return 0;
> }
>
> But run these codes in my IDE, I do not say anything wrong in my system. So 
> could anyone help? 

And what did you expect it to do?

malloc() attempts to allocate the requested amount of memory.  If it
succeeds, it returns a pointer to it.  If it fails, it returns a null
pointer.  Since you didn't check the value returned by malloc(), you
have no way of knowing whether it succeeded.

If malloc() fails, it doesn't print an error message or crash your
program, it just tells you that it failed by returning a null pointer
value.  You have to decide for yourself how to respond to a failure.

Never cast the result of malloc().  Always check the value returned by
malloc().  The comp.lang.c FAQ is at <http://www.c-faq.com/>; read
questions 7.6, 7.7, 7.7a, and 7.7b.  (Then read the rest of the FAQ.)

The "putchar(77);" statement prints a single character with the value
77.  (This is 'M' if you happen to have an ASCII-based system.  I
think it's a left parenthesis in EBCDIC.)

I suppose the intent is to print some output to let you know that the
malloc() calls have completed, but since there's no newline, it's not
guaranteed that the output will appear.  I can't imagine why you chose
to print character 77.  If you really want to print an 'M', just use
"putchar('M');".  It would have been much clearer to use something
like
    printf("mallocs done\n");
but I'm going to do something else; see below.

You have two calls to getchar().  One call would be understandable; on
some systems, particularly Windows, some methods of executing programs
will close the output window immediately after the program finishes.
A better way to handle this is to use a different method to execute
the program.  You can run it from a command window, or you can execute
it from your IDE with an option to keep the window open.  (I don't
know how to do this; consult your system's documentation.)  I have no
idea why you need two calls to getchar().

Here's a modified version of your program:
==================================================
#include <stdlib.h>
#include<stdio.h>

#define MAX 1000000000

int main(void)
{
    long double  *temp = (long double*)malloc (MAX * sizeof(long double));
    long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));

    if (temp == NULL) {
        printf("temp  is a null pointer\n");
    }
    else {
        printf("temp  = %p\n", (void*)temp);
    }
    if (temp1 == NULL) {
        printf("temp1 is a null pointer\n");
    }
    else {
        printf("temp1 = %p\n", (void*)temp1);
    }

    return 0;
}
==================================================

I could have just used
    printf("temp  = %p\n", (void*)temp);

to show the value of temp whether it's a null pointer or not, but the
text representation of a null pointer can vary from one system to
another.  By explicitly checking whether it's equal to NULL, we make
the output more obvious.  (And, if you were actually going to use the
allocated space, you'd need to do this check anyway.)

And here's the output I got:

temp  is a null pointer
temp1 is a null pointer

There are some good things in your program that I didn't have to
change.  You have the #include directives for the required headers,
you properly declared "int main(void)", and you have a "return 0;" at
the end of main().  Too many people leave these out.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.
0
kst-u (21963)
8/17/2006 8:34:39 PM
Chen Shusheng wrote:
> #define MAX 1000000000
>
> int main(void)
> {
>     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
>     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));

MAX * sizeof(long double) is probably not fitting in size_t, so you're
not trying to allocate the amount you think you are.

0
tu102 (102)
8/17/2006 9:13:53 PM
"tedu" <tu@zeitbombe.org> writes:
> Chen Shusheng wrote:
>> #define MAX 1000000000
>>
>> int main(void)
>> {
>>     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
>>     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));
>
> MAX * sizeof(long double) is probably not fitting in size_t, so you're
> not trying to allocate the amount you think you are.

Yes, that's another possibility.  MAX is one billion; sizeof(long
double) is typically 8, 12, or 16, and any of those will exceed the
maximum value of a 32-bit size_t.  Since unsigned arithmetic
doesn't overflow, the compiler won't warn about this.

As it turns out, even if size_t is 32 bits and sizeof(long double) is
either 8, 12, or 16 (none of these are guaranteed), the result of the
multiplication is still a very large number, almost certainly more
than the amount of memory a program will be able to allocate.  It's
still necessary to check the result of malloc().

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.
0
kst-u (21963)
8/17/2006 10:51:14 PM
On Thu, 17 Aug 2006 08:37:49 UTC, "Chen Shusheng" 
<lyrachina@hotmail.tom> wrote:

> Hi all,
> 
> In fact, I want to let my memory run out. And see what will happen. My 
> system is windowsXp. Memory is 256M.I think my cdes will apply more memory 
> than I have. Codes are below:
> 
> #include <stdlib.h>
> #include<stdio.h>
> 
> #define MAX 1000000000

Who says that this is a legal int? 
 
> int main(void)
> {
>     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
>     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));

Never ever cast the result of malloc(). At best you'll end up in the 
lands of undefined behavior, at worsest you'll suppress any diagnostic
the compiler may give you.

You have no access to temp and tmp. So the compiler may decide to 
throw away the whole lines or even temp and temp1 becaue you does 
nothing with them, not even check the result of malloc().

malloc() accepts only int as parameter, so you may get a diagnostic 
from the compiler and you tries to ignore it. Set up the warning level
of your compiler.

>     putchar(77);

What does that mean? Printing a decimal 77 means nothing

>     getchar();
>     getchar();
> 
>     return 0;
> }
> 
> But run these codes in my IDE, I do not say anything wrong in my system. So 
> could anyone help? 
> 
> 
Read what your documentation says about malloc() and you'll have no 
need to run your program anyway.

-- 
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
0
os2guy1 (1090)
8/18/2006 5:50:09 AM
"Herbert Rosenau" <os2guy@pc-rosenau.de> writes:

> On Thu, 17 Aug 2006 08:37:49 UTC, "Chen Shusheng" 
> <lyrachina@hotmail.tom> wrote:
>
>> Hi all,
>> 
>> In fact, I want to let my memory run out. And see what will happen. My 
>> system is windowsXp. Memory is 256M.I think my cdes will apply more memory 
>> than I have. Codes are below:
>> 
>> #include <stdlib.h>
>> #include<stdio.h>
>> 
>> #define MAX 1000000000
>
> Who says that this is a legal int? 
>

The maximum guaranteed legal int is 32767. Just so the OP knows.
  
>> int main(void)
>> {
>>     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
>>     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));
>
> Never ever cast the result of malloc(). At best you'll end up in the 
> lands of undefined behavior, at worsest you'll suppress any diagnostic
> the compiler may give you.
>

At best you'll have poor style; at worst you'll have undefined behavior.
Almost by definition, UB can't be a "best case".

> You have no access to temp and tmp. So the compiler may decide to 
> throw away the whole lines or even temp and temp1 becaue you does 
> nothing with them, not even check the result of malloc().
>

If the compiler is allowed to do this, it means that those lines are
irrelevant and should be removed. Having not seen the OP's code, I'm
not sure what kind of situation this is.

> malloc() accepts only int as parameter, so you may get a diagnostic 
> from the compiler and you tries to ignore it. Set up the warning level
> of your compiler.
>

Correction: malloc() accepts only /size_t/ as a parameter, although any
integer type will work (provided you have an appropriate prototype in
scope).

>>     putchar(77);
>
> What does that mean? Printing a decimal 77 means nothing
>

And in the absense of a fflush (stdout), may very well /do/ nothing, at
least not immediately. I would like to know what the OP meant by 77,
though; in ASCII that would be a 'M', I believe. Why didn't he just
write 'M' in the first place. (Or whatever he might have meant by 77.)

>>     getchar();
>>     getchar();
>> 
>>     return 0;
>> }
>> 
>> But run these codes in my IDE, I do not say anything wrong in my system. So 
>> could anyone help? 
>> 

You cannot "run these codes", Chen; you can only compile them. Whether or
not you have an IDE is irrelevant. (Though if you do, it's statistically
more likely that you aren't compiling as standard C. Check your options.)

-- 
Andrew Poelstra       <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?"  -Anon.
0
8/18/2006 6:11:24 AM
printf("temp1 = %p\n", (void*)temp1);

Could you pls explain why you use (void *) bfor ptr temp1?

Keith Thompson wrote:
> "Chen Shusheng" <lyrachina@hotmail.tom> writes:
> > In fact, I want to let my memory run out. And see what will happen. My
> > system is windowsXp. Memory is 256M.I think my cdes will apply more memory
> > than I have. Codes are below:
> >
> > #include <stdlib.h>
> > #include<stdio.h>
> >
> > #define MAX 1000000000
> >
> > int main(void)
> > {
> >     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
> >     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));
> >     putchar(77);
> >     getchar();
> >     getchar();
> >
> >     return 0;
> > }
> >
> > But run these codes in my IDE, I do not say anything wrong in my system. So
> > could anyone help?
>
> And what did you expect it to do?
>
> malloc() attempts to allocate the requested amount of memory.  If it
> succeeds, it returns a pointer to it.  If it fails, it returns a null
> pointer.  Since you didn't check the value returned by malloc(), you
> have no way of knowing whether it succeeded.
>
> If malloc() fails, it doesn't print an error message or crash your
> program, it just tells you that it failed by returning a null pointer
> value.  You have to decide for yourself how to respond to a failure.
>
> Never cast the result of malloc().  Always check the value returned by
> malloc().  The comp.lang.c FAQ is at <http://www.c-faq.com/>; read
> questions 7.6, 7.7, 7.7a, and 7.7b.  (Then read the rest of the FAQ.)
>
> The "putchar(77);" statement prints a single character with the value
> 77.  (This is 'M' if you happen to have an ASCII-based system.  I
> think it's a left parenthesis in EBCDIC.)
>
> I suppose the intent is to print some output to let you know that the
> malloc() calls have completed, but since there's no newline, it's not
> guaranteed that the output will appear.  I can't imagine why you chose
> to print character 77.  If you really want to print an 'M', just use
> "putchar('M');".  It would have been much clearer to use something
> like
>     printf("mallocs done\n");
> but I'm going to do something else; see below.
>
> You have two calls to getchar().  One call would be understandable; on
> some systems, particularly Windows, some methods of executing programs
> will close the output window immediately after the program finishes.
> A better way to handle this is to use a different method to execute
> the program.  You can run it from a command window, or you can execute
> it from your IDE with an option to keep the window open.  (I don't
> know how to do this; consult your system's documentation.)  I have no
> idea why you need two calls to getchar().
>
> Here's a modified version of your program:
> ==================================================
> #include <stdlib.h>
> #include<stdio.h>
>
> #define MAX 1000000000
>
> int main(void)
> {
>     long double  *temp = (long double*)malloc (MAX * sizeof(long double));
>     long double  *temp1 = (long double*)malloc (MAX * sizeof(long double));
>
>     if (temp == NULL) {
>         printf("temp  is a null pointer\n");
>     }
>     else {
>         printf("temp  = %p\n", (void*)temp);
>     }
>     if (temp1 == NULL) {
>         printf("temp1 is a null pointer\n");
>     }
>     else {
>         printf("temp1 = %p\n", (void*)temp1);
>     }
>
>     return 0;
> }
> ==================================================
>
> I could have just used
>     printf("temp  = %p\n", (void*)temp);
>
> to show the value of temp whether it's a null pointer or not, but the
> text representation of a null pointer can vary from one system to
> another.  By explicitly checking whether it's equal to NULL, we make
> the output more obvious.  (And, if you were actually going to use the
> allocated space, you'd need to do this check anyway.)
>
> And here's the output I got:
>
> temp  is a null pointer
> temp1 is a null pointer
>
> There are some good things in your program that I didn't have to
> change.  You have the #include directives for the required headers,
> you properly declared "int main(void)", and you have a "return 0;" at
> the end of main().  Too many people leave these out.
>
> --
> Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
> San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
> We must do something.  This is something.  Therefore, we must do this.

0
csshine (30)
8/18/2006 9:48:10 AM
csshine@gmail.com writes:
> printf("temp1 = %p\n", (void*)temp1);
>
> Could you pls explain why you use (void *) bfor ptr temp1?

Please learn how to post properly.  Don't top-post; see
<http://www.caliburn.nl/topposting.html>.  It's not necessary to quote
the entire article to which you're replying; take the time to trim
anything not relevant to your response.  The idea is to quote enough
material so your followup makes sense on its own, not to repeat
everything that's been written so far.  See most of the articles in
this newsgroups for examples of how it's done.

In answer to your question, the "%p" format requires a void* argument.
temp is of type long double*.  (This is one of the few cases where a
cast is appropriate.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.
0
kst-u (21963)
8/18/2006 11:07:35 AM
jaysome wrote:

> That's not a very good example. According to the C Standard:
>
> "The value of the RAND_MAX macro shall be at least 32767."
>
> Three of your four lines of code could very well lead to undefined
> behavior on a bunch of implementations.
>
> Best regards
> --
> jay

You'r 100% correct.  I was sloppy. It should be more like:

    index = random() % MAX;

But the main point still stands, you can malloc() huge amounts of
"memory", but it isnt always useful memory.  It's quite a jump from an
array element that can be accssed in 3nsec versus having to wait oh,
say 300 msec.  One Hundred Million times slower by my calculation.

0
grg2 (355)
8/18/2006 11:53:06 AM
"Ancient_Hacker" <grg2@comcast.net> wrote in message
news:1155901986.337733.241460@m79g2000cwm.googlegroups.com...
>
> jaysome wrote:
>
> > That's not a very good example. According to the C Standard:
> >
> > "The value of the RAND_MAX macro shall be at least 32767."
> >
> > Three of your four lines of code could very well lead to undefined
> > behavior on a bunch of implementations.
> >
> > Best regards
> > --
> > jay
>
> You'r 100% correct.  I was sloppy. It should be more like:
>
>     index = random() % MAX;

That's still not very good. See FAQ question 13.16.

Philip

0
8/18/2006 1:30:19 PM
Ancient_Hacker wrote:
> Chen Shusheng wrote:
> > Hi all,
> >
> > In fact, I want to let my memory run out. And see what will happen. My
> > system is windowsXp. Memory is 256M.I think my cdes will apply more memory
> > than I have. Codes are below:
>
> > But run these codes in my IDE, I do not say anything wrong in my system. So
> > could anyone help?
>
> The system allocated the memory, but most of it sat on the disk as
> virtual pages in the virtual swap file.
>
> To actually exercise the memory, try setting each element of the array,
> preferably at random.    Then leave for a 6-month vacation.  It may
> take that long for the whole array to be populated.  Example:
>
> for( i = 0; i < MAX; i++ ) {
>        index = rand() * MAX;
>       temp1[ index ] = 123.456;
>       temp2[ index ] = 456.789;
>  }

Perhaps the original poster want to experience how memory leak is. This
may help.

#include <stdlib.h>
int main(void){
  for(;;) malloc(1);
  return 0;
}

0
8/18/2006 3:32:37 PM
Reply:
Similar artilces about - "define" and "malloc" more:

Where is malloc_size() defined?
I use my own implementation of a bytebuffer which uses the following dealloc method: - (void) dealloc { if (buffer != NULL) { free(buffer); } [super dealloc]; } With "Jaguar" MacOS X and a WebObjects 4.5.1 installation this failed and I had to change it to this one: - (void) dealloc { if (malloc_size(buffer) > 0) { free(buffer); } [super dealloc]; } But I allways get an "implicit declaration of function malloc_size" warning while installing the framework. Where is this function defined? I've tried <sys/malloc.h> and <stdli...

"define" and "malloc" more
Hi all, In fact, I want to let my memory run out. And see what will happen. My system is windowsXp. Memory is 256M.I think my cdes will apply more memory than I have. Codes are below: #include <stdlib.h> #include<stdio.h> #define MAX 1000000000 int main(void) { long double *temp = (long double*)malloc (MAX * sizeof(long double)); long double *temp1 = (long double*)malloc (MAX * sizeof(long double)); putchar(77); getchar(); getchar(); return 0; } But run these codes in my IDE, I do not say anything wrong in my system. So could anyone help? ever...

Question about "define" and "malloc"
CSS white here: Simply strange, I found "define" can not work with "malloc". Together my complier will say "parse error". Could anyone tell me why? ------------------------- #define MAX 10000 ....... int main(void){ ..... char * temp=(char *)malloc(MAX*sizeof(char)); ..... system("pause"); return 0; } when complying, wrong. look for explanation. Chen Shusheng wrote: > CSS white here: what? > Simply strange, I found "define" can not work with "malloc". you are mistaken > Together my complier will say "parse er...

#define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))
Consider the following macro: #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type))) The intent is to wrap raw memory allocation of N bytes into a macro which returns allocated chunk of memory to be used as a Type structure. The background: I was beaten many times (it surely is not my exclusive experience) by functions which return and accept void*. There are such functions, and there are cases when you can't do much about it (third-party libraries, containers, etc.). I make a conclusion: void* is evil and must be avoided when possible and easy. Therefore I believe it's better to use...

Can I replace malloc and cousins with mxMalloc etc. using #defines?
Hello, I am wondering if it is possible to take some code written in standard C++ and C, and replace all calls to malloc and similar with calls to mxMalloc using preprocessor directives. I have succesfully done this with mexPrintf, where I simply pass the following directive to the compiler when building the code as part of a mexfuntion: -D"printf=mexPrintf" This seems to work. Can I safely do something similar such as: #define malloc mxMalloc to replace all calls to malloc with mxMalloc? The purpose of this would be so that I could attach a large dataset to a ma...

malloc undefined when cross comiling wx application for mingw32
I have installed the cross toolchain with - binutils 2.15.94.0.2 configure --prefix=/opt/compilers --host=i486-pc-linux-gnu \ --build=i486-pc-linux-gnu --target=i486-mingw32 --infodir=/tmp \ --mandir=/tmp --datadir=$PREFIX/i486-mingw32/share make make gnulocaledir=/tmp localedir=/tmp install gcc 3.4.3 configure --prefix=/opt/compilers -host=i486-pc-linux-gnu \ --build=i486-pc-linux-gnu --target=i486-mingw32 --infodir=/tmp \ --enable-threads=win32 \ --mandir=/tmp --datadir=$PREFIX/i486-mingw32/share make make -C gnatlib make gnulocaledir=/tmp localedir=/tmp ins...