472,958 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

malloc behavior on failure

I originally posted the following code in a group discussing threads
but after further research I think I have a c question about the code.
I know there are a couple of non standard c includes here and the POSIX
stuff is non standard but this is how I stumbled onto this question.

#include <INTEGRITY.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>

timer_t l_timer_2;
int counter =0;

//void Test(union sigval sigval)
void Test (union sigval sigval)
{
printf("Count\n");
counter++;

return;
}
int main()
{
struct itimerspec l_timer_spec1;
struct sigevent l_tevent1;
int *ptr;
int status;

l_tevent1.sigev_notify = SIGEV_THREAD;
l_tevent1.sigev_value.sival_ptr = &l_timer_2;
l_tevent1.sigev_notify_function = Test;
l_tevent1.sigev_notify_attributes = NULL;
l_tevent1.sigev_signo = SIGRTMIN;
l_timer_spec1.it_interval.tv_sec = 2;
l_timer_spec1.it_interval.tv_nsec = 0;
//set subsequent timer intervals
l_timer_spec1.it_value.tv_sec = 2;
l_timer_spec1.it_value.tv_nsec = 0;

//create timer
if (timer_create(CLOCK_REALTIME, &l_tevent1, &l_timer_2) < 0)
{
status = 1;
}

if (status == 0)
{
if (timer_settime(l_timer_2, 0, &l_timer_spec1, NULL) < 0 )
{
status = 1;
}
}

ptr = malloc(1000000);

if (ptr == NULL)
printf("NULL PTR\n");

counter++;

Exit(0);
}

Now I know this code snipet is pretty useless but it was the result of
troubleshooting a problem. When the malloc fails the timer stops
operating as expected. After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops. So my question is what, if anything, does the
standard have to say about the behavior of malloc in this situation. Is
this behavior allowed and if so is it common. It seems to me that there
are many more gracefull ways for this to fail.

Feb 28 '06 #1
12 3230
On 27 Feb 2006 16:38:01 -0800, "gooch" <go******@comcast.net> wrote in
comp.lang.c:
I originally posted the following code in a group discussing threads
but after further research I think I have a c question about the code.
I know there are a couple of non standard c includes here and the POSIX
stuff is non standard but this is how I stumbled onto this question.

#include <INTEGRITY.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>

timer_t l_timer_2;
int counter =0;

//void Test(union sigval sigval)
void Test (union sigval sigval)
{
printf("Count\n");
counter++;

return;
}
int main()
{
struct itimerspec l_timer_spec1;
struct sigevent l_tevent1;
int *ptr;
int status;

l_tevent1.sigev_notify = SIGEV_THREAD;
l_tevent1.sigev_value.sival_ptr = &l_timer_2;
l_tevent1.sigev_notify_function = Test;
l_tevent1.sigev_notify_attributes = NULL;
l_tevent1.sigev_signo = SIGRTMIN;
l_timer_spec1.it_interval.tv_sec = 2;
l_timer_spec1.it_interval.tv_nsec = 0;
//set subsequent timer intervals
l_timer_spec1.it_value.tv_sec = 2;
l_timer_spec1.it_value.tv_nsec = 0;

//create timer
if (timer_create(CLOCK_REALTIME, &l_tevent1, &l_timer_2) < 0)
{
status = 1;
}

if (status == 0)
{
if (timer_settime(l_timer_2, 0, &l_timer_spec1, NULL) < 0 )
{
status = 1;
}
}

ptr = malloc(1000000);

if (ptr == NULL)
printf("NULL PTR\n");

counter++;

Exit(0);
}

Now I know this code snipet is pretty useless but it was the result of
troubleshooting a problem. When the malloc fails the timer stops
operating as expected. After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops. So my question is what, if anything, does the
standard have to say about the behavior of malloc in this situation. Is
this behavior allowed and if so is it common. It seems to me that there
are many more gracefull ways for this to fail.


How do you know that the standard C library function malloc() is doing
what you say it is? How do you know it is not the behavior of your
proprietary commercial operating system?

Your program is littered with things that do not exist in standard C.
C does not know or care about "timers popping" or "threads".

You don't even have convincing proof that the failed memory allocation
is at fault, and in fact you can't prove that for sure in a strictly
conforming program. Nevertheless, you could try. When the attempt to
allocate 1,000,000 bytes fails, what is the result if you immediately
try a smaller allocation, say 1 byte? Without the threads and popping
timers.

I'd suggest you talk to Green Hills technical support. You have an
implementation specific issue, not a language one.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 28 '06 #2

Jack Klein wrote:
On 27 Feb 2006 16:38:01 -0800, "gooch" <go******@comcast.net> wrote in
comp.lang.c:
I originally posted the following code in a group discussing threads
but after further research I think I have a c question about the code.
I know there are a couple of non standard c includes here and the POSIX
stuff is non standard but this is how I stumbled onto this question.

#include <INTEGRITY.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>

timer_t l_timer_2;
int counter =0;

//void Test(union sigval sigval)
void Test (union sigval sigval)
{
printf("Count\n");
counter++;

return;
}
int main()
{
struct itimerspec l_timer_spec1;
struct sigevent l_tevent1;
int *ptr;
int status;

l_tevent1.sigev_notify = SIGEV_THREAD;
l_tevent1.sigev_value.sival_ptr = &l_timer_2;
l_tevent1.sigev_notify_function = Test;
l_tevent1.sigev_notify_attributes = NULL;
l_tevent1.sigev_signo = SIGRTMIN;
l_timer_spec1.it_interval.tv_sec = 2;
l_timer_spec1.it_interval.tv_nsec = 0;
//set subsequent timer intervals
l_timer_spec1.it_value.tv_sec = 2;
l_timer_spec1.it_value.tv_nsec = 0;

//create timer
if (timer_create(CLOCK_REALTIME, &l_tevent1, &l_timer_2) < 0)
{
status = 1;
}

if (status == 0)
{
if (timer_settime(l_timer_2, 0, &l_timer_spec1, NULL) < 0 )
{
status = 1;
}
}

ptr = malloc(1000000);

if (ptr == NULL)
printf("NULL PTR\n");

counter++;

Exit(0);
}

Now I know this code snipet is pretty useless but it was the result of
troubleshooting a problem. When the malloc fails the timer stops
operating as expected. After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops. So my question is what, if anything, does the
standard have to say about the behavior of malloc in this situation. Is
this behavior allowed and if so is it common. It seems to me that there
are many more gracefull ways for this to fail.
How do you know that the standard C library function malloc() is doing
what you say it is? How do you know it is not the behavior of your
proprietary commercial operating system?

Your program is littered with things that do not exist in standard C.
C does not know or care about "timers popping" or "threads".

You don't even have convincing proof that the failed memory allocation
is at fault, and in fact you can't prove that for sure in a strictly
conforming program.


Upon entering malloc a resource analyzer shows much memory available.
Once malloc fails 100% of resources are utilized. Proof enough for you.
Nevertheless, you could try. When the attempt to
allocate 1,000,000 bytes fails, what is the result if you immediately
try a smaller allocation, say 1 byte? Without the threads and popping
timers.

I'd suggest you talk to Green Hills technical support. You have an
implementation specific issue, not a language one.


My question is language specific. Ignore the code if you would like to
and just read the question but the question has nothing to do with the
implementation.

Feb 28 '06 #3
gooch wrote:
I originally posted the following code in a group discussing threads
but after further research I think I have a c question about the code.
I know there are a couple of non standard c includes here and the
POSIX stuff is non standard but this is how I stumbled onto this
question.

#include <INTEGRITY.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>

timer_t l_timer_2;
int counter =0;

//void Test(union sigval sigval)
void Test (union sigval sigval)
{
printf("Count\n");
counter++;

return;
}
int main()
{
struct itimerspec l_timer_spec1;
struct sigevent l_tevent1;
int *ptr;
int status;

l_tevent1.sigev_notify = SIGEV_THREAD;
l_tevent1.sigev_value.sival_ptr = &l_timer_2;
l_tevent1.sigev_notify_function = Test;
l_tevent1.sigev_notify_attributes = NULL;
l_tevent1.sigev_signo = SIGRTMIN;
l_timer_spec1.it_interval.tv_sec = 2;
l_timer_spec1.it_interval.tv_nsec = 0;
//set subsequent timer intervals
l_timer_spec1.it_value.tv_sec = 2;
l_timer_spec1.it_value.tv_nsec = 0;

//create timer
if (timer_create(CLOCK_REALTIME, &l_tevent1, &l_timer_2) < 0)
{
status = 1;
}

if (status == 0)
{
if (timer_settime(l_timer_2, 0, &l_timer_spec1, NULL) < 0 )
{
status = 1;
}
}

ptr = malloc(1000000);

if (ptr == NULL)
printf("NULL PTR\n");

counter++;

Exit(0);
}

Now I know this code snipet is pretty useless but it was the result of
troubleshooting a problem. When the malloc fails the timer stops
operating as expected. After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops. So my question is what, if anything, does the standard have to say about
the behavior of malloc in this situation. Is this behavior allowed and if so is it common. It seems to me that
there are many more gracefull ways for this to fail.


From the c99 standard on malloc ...
"If the space cannot be allocated, a null pointer is returned"

And that's it.

--
==============
Not a pedant
==============
Feb 28 '06 #4

pemo wrote:
gooch wrote:
I originally posted the following code in a group discussing threads
but after further research I think I have a c question about the code.
I know there are a couple of non standard c includes here and the
POSIX stuff is non standard but this is how I stumbled onto this
question.

#include <INTEGRITY.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <time.h>

timer_t l_timer_2;
int counter =0;

//void Test(union sigval sigval)
void Test (union sigval sigval)
{
printf("Count\n");
counter++;

return;
}
int main()
{
struct itimerspec l_timer_spec1;
struct sigevent l_tevent1;
int *ptr;
int status;

l_tevent1.sigev_notify = SIGEV_THREAD;
l_tevent1.sigev_value.sival_ptr = &l_timer_2;
l_tevent1.sigev_notify_function = Test;
l_tevent1.sigev_notify_attributes = NULL;
l_tevent1.sigev_signo = SIGRTMIN;
l_timer_spec1.it_interval.tv_sec = 2;
l_timer_spec1.it_interval.tv_nsec = 0;
//set subsequent timer intervals
l_timer_spec1.it_value.tv_sec = 2;
l_timer_spec1.it_value.tv_nsec = 0;

//create timer
if (timer_create(CLOCK_REALTIME, &l_tevent1, &l_timer_2) < 0)
{
status = 1;
}

if (status == 0)
{
if (timer_settime(l_timer_2, 0, &l_timer_spec1, NULL) < 0 )
{
status = 1;
}
}

ptr = malloc(1000000);

if (ptr == NULL)
printf("NULL PTR\n");

counter++;

Exit(0);
}

Now I know this code snipet is pretty useless but it was the result of
troubleshooting a problem. When the malloc fails the timer stops
operating as expected. After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops.

So my question is what, if anything, does the standard have to say about
the behavior of malloc in this situation.

Is this behavior allowed and if so is it common. It seems to me that
there are many more gracefull ways for this to fail.


From the c99 standard on malloc ...
"If the space cannot be allocated, a null pointer is returned"

And that's it.


Thanks. That is what I was looking for.

Feb 28 '06 #5
On 27 Feb 2006 16:38:01 -0800, "gooch" <go******@comcast.net> wrote:
After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops. So my question is what, if anything, does the
standard have to say about the behavior of malloc in this situation.
Nothing, except that the function returns NULL.
Is
this behavior allowed and if so is it common. It seems to me that there
are many more gracefull ways for this to fail.


Apparently it's allowed, but I don't think it's common, nor does it
make sense. Systems that I've worked with don't use any memory on a
failed allocation.

It's a quality of implementation issue - talk to the vendor.

--
Al Balmer
Sun City, AZ
Feb 28 '06 #6

Al Balmer wrote:
On 27 Feb 2006 16:38:01 -0800, "gooch" <go******@comcast.net> wrote:
After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops. So my question is what, if anything, does the
standard have to say about the behavior of malloc in this situation.


Nothing, except that the function returns NULL.
Is
this behavior allowed and if so is it common. It seems to me that there
are many more gracefull ways for this to fail.


Apparently it's allowed, but I don't think it's common, nor does it
make sense. Systems that I've worked with don't use any memory on a
failed allocation.

It's a quality of implementation issue - talk to the vendor.

Yeah, I have already contacted the vendor but I was just curious as to
what the standard has to say about this.

Thanks for the input.

Feb 28 '06 #7
On 2006-02-28, gooch <go******@comcast.net> wrote:

Jack Klein wrote:
On 27 Feb 2006 16:38:01 -0800, "gooch" <go******@comcast.net> wrote in
comp.lang.c:
> I originally posted the following code in a group discussing threads
> but after further research I think I have a c question about the code.
> I know there are a couple of non standard c includes here and the POSIX
> stuff is non standard but this is how I stumbled onto this question.
>
> #include <INTEGRITY.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <pthread.h>
> #include <signal.h>
> #include <time.h>
>
> timer_t l_timer_2;
> int counter =0;
>
> //void Test(union sigval sigval)
> void Test (union sigval sigval)
> {
> printf("Count\n");
> counter++;
>
> return;
> }
>
>
> int main()
> {
> struct itimerspec l_timer_spec1;
> struct sigevent l_tevent1;
> int *ptr;
> int status;
>
> l_tevent1.sigev_notify = SIGEV_THREAD;
> l_tevent1.sigev_value.sival_ptr = &l_timer_2;
> l_tevent1.sigev_notify_function = Test;
> l_tevent1.sigev_notify_attributes = NULL;
> l_tevent1.sigev_signo = SIGRTMIN;
> l_timer_spec1.it_interval.tv_sec = 2;
> l_timer_spec1.it_interval.tv_nsec = 0;
> //set subsequent timer intervals
> l_timer_spec1.it_value.tv_sec = 2;
> l_timer_spec1.it_value.tv_nsec = 0;
>
> //create timer
> if (timer_create(CLOCK_REALTIME, &l_tevent1, &l_timer_2) < 0)
> {
> status = 1;
> }
>
> if (status == 0)
> {
> if (timer_settime(l_timer_2, 0, &l_timer_spec1, NULL) < 0 )
> {
> status = 1;
> }
> }
>
> ptr = malloc(1000000);
>
> if (ptr == NULL)
> printf("NULL PTR\n");
>
> counter++;
>
> Exit(0);
> }
>
> Now I know this code snipet is pretty useless but it was the result of
> troubleshooting a problem. When the malloc fails the timer stops
> operating as expected. After some research it appears that when malloc
> fails, returns NULL, due to not enough resources it actually marks all
> the available memory as allocated. Due to this the timer can't start
> the thread when it pops. So my question is what, if anything, does the
> standard have to say about the behavior of malloc in this situation. Is
> this behavior allowed and if so is it common. It seems to me that there
> are many more gracefull ways for this to fail.
How do you know that the standard C library function malloc() is doing
what you say it is? How do you know it is not the behavior of your
proprietary commercial operating system?

Your program is littered with things that do not exist in standard C.
C does not know or care about "timers popping" or "threads".

You don't even have convincing proof that the failed memory allocation
is at fault, and in fact you can't prove that for sure in a strictly
conforming program.


Upon entering malloc a resource analyzer shows much memory available.
Once malloc fails 100% of resources are utilized. Proof enough for you.


No, that's not "proof enough" - no-one here knows how their resource
analyzer works. I'll tell you how a typical malloc implementation works,
though - it grabs a large chunk of memory from the system all at once
and passes it out in smaller chunks to each malloc request. It's
possible that the large chunk might be seen by the "resource analyzer"
as being utilized.
Nevertheless, you could try. When the attempt to
allocate 1,000,000 bytes fails, what is the result if you immediately
try a smaller allocation, say 1 byte? Without the threads and popping
timers.

I'd suggest you talk to Green Hills technical support. You have an
implementation specific issue, not a language one.


My question is language specific.


It's specific to a particular implementation of the language. Which
makes it their problem, and not ours.
Ignore the code if you would like to and just read the question but
the question has nothing to do with the implementation.

Feb 28 '06 #8

Jordan Abel wrote:
On 2006-02-28, gooch <go******@comcast.net> wrote:

Jack Klein wrote:
On 27 Feb 2006 16:38:01 -0800, "gooch" <go******@comcast.net> wrote in
comp.lang.c:

> I originally posted the following code in a group discussing threads
> but after further research I think I have a c question about the code.
> I know there are a couple of non standard c includes here and the POSIX
> stuff is non standard but this is how I stumbled onto this question.
>
> #include <INTEGRITY.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <pthread.h>
> #include <signal.h>
> #include <time.h>
>
> timer_t l_timer_2;
> int counter =0;
>
> //void Test(union sigval sigval)
> void Test (union sigval sigval)
> {
> printf("Count\n");
> counter++;
>
> return;
> }
>
>
> int main()
> {
> struct itimerspec l_timer_spec1;
> struct sigevent l_tevent1;
> int *ptr;
> int status;
>
> l_tevent1.sigev_notify = SIGEV_THREAD;
> l_tevent1.sigev_value.sival_ptr = &l_timer_2;
> l_tevent1.sigev_notify_function = Test;
> l_tevent1.sigev_notify_attributes = NULL;
> l_tevent1.sigev_signo = SIGRTMIN;
> l_timer_spec1.it_interval.tv_sec = 2;
> l_timer_spec1.it_interval.tv_nsec = 0;
> //set subsequent timer intervals
> l_timer_spec1.it_value.tv_sec = 2;
> l_timer_spec1.it_value.tv_nsec = 0;
>
> //create timer
> if (timer_create(CLOCK_REALTIME, &l_tevent1, &l_timer_2) < 0)
> {
> status = 1;
> }
>
> if (status == 0)
> {
> if (timer_settime(l_timer_2, 0, &l_timer_spec1, NULL) < 0 )
> {
> status = 1;
> }
> }
>
> ptr = malloc(1000000);
>
> if (ptr == NULL)
> printf("NULL PTR\n");
>
> counter++;
>
> Exit(0);
> }
>
> Now I know this code snipet is pretty useless but it was the result of
> troubleshooting a problem. When the malloc fails the timer stops
> operating as expected. After some research it appears that when malloc
> fails, returns NULL, due to not enough resources it actually marks all
> the available memory as allocated. Due to this the timer can't start
> the thread when it pops. So my question is what, if anything, does the
> standard have to say about the behavior of malloc in this situation. Is
> this behavior allowed and if so is it common. It seems to me that there
> are many more gracefull ways for this to fail.

How do you know that the standard C library function malloc() is doing
what you say it is? How do you know it is not the behavior of your
proprietary commercial operating system?

Your program is littered with things that do not exist in standard C.
C does not know or care about "timers popping" or "threads".

You don't even have convincing proof that the failed memory allocation
is at fault, and in fact you can't prove that for sure in a strictly
conforming program.


Upon entering malloc a resource analyzer shows much memory available.
Once malloc fails 100% of resources are utilized. Proof enough for you.


No, that's not "proof enough" - no-one here knows how their resource
analyzer works. I'll tell you how a typical malloc implementation works,
though - it grabs a large chunk of memory from the system all at once
and passes it out in smaller chunks to each malloc request. It's
possible that the large chunk might be seen by the "resource analyzer"
as being utilized.
Nevertheless, you could try. When the attempt to
allocate 1,000,000 bytes fails, what is the result if you immediately
try a smaller allocation, say 1 byte? Without the threads and popping
timers.

I'd suggest you talk to Green Hills technical support. You have an
implementation specific issue, not a language one.


My question is language specific.


It's specific to a particular implementation of the language. Which
makes it their problem, and not ours.


No my question was what does the standard have to say about the
behavior of malloc if it fails, if anything. This question makes no
assumtion about any implementation. Perhaps I could have worded the
question a little clearer but it is not an implementation specific
question.

Feb 28 '06 #9
On 28 Feb 2006 12:44:51 -0800, "gooch" <go******@comcast.net> wrote:
It's specific to a particular implementation of the language. Which
makes it their problem, and not ours.


No my question was what does the standard have to say about the
behavior of malloc if it fails, if anything. This question makes no
assumtion about any implementation. Perhaps I could have worded the
question a little clearer but it is not an implementation specific
question.


While we're bashing you <g>, a word about editing. At least 100 lines
of your post was unneeded for your reply.

--
Al Balmer
Sun City, AZ
Feb 28 '06 #10

While we're bashing you <g>, a word about editing. At least 100 lines
of your post was unneeded for your reply.

Sorry about that. I will keep that in mind. Thanks again for the
response earlier.

Feb 28 '06 #11
gooch wrote:
Al Balmer wrote:

While we're bashing you <g>, a word about editing. At least 100 lines
of your post was unneeded for your reply.

Sorry about that. I will keep that in mind. Thanks again for the
response earlier.


And while we're still at it: ;o)

Do not snip attribution lines -- it's important to know who said what.

Keep up the good work!

--
BR, Vladimir

How come only your friends step on your new white sneakers?

Feb 28 '06 #12
In article <11*********************@v46g2000cwv.googlegroups. com>,
"gooch" <go******@comcast.net> wrote:
Al Balmer wrote:
On 27 Feb 2006 16:38:01 -0800, "gooch" <go******@comcast.net> wrote:
After some research it appears that when malloc
fails, returns NULL, due to not enough resources it actually marks all
the available memory as allocated. Due to this the timer can't start
the thread when it pops. So my question is what, if anything, does the
standard have to say about the behavior of malloc in this situation.


Nothing, except that the function returns NULL.
Is
this behavior allowed and if so is it common. It seems to me that there
are many more gracefull ways for this to fail.


Apparently it's allowed, but I don't think it's common, nor does it
make sense. Systems that I've worked with don't use any memory on a
failed allocation.

It's a quality of implementation issue - talk to the vendor.

Yeah, I have already contacted the vendor but I was just curious as to
what the standard has to say about this.


According to the C Standard, _any_ call to malloc could fail, returning
NULL. The rest is "quality of implementation". But if you have enough
memory for say malloc (900000) to succeed, and malloc (1000000) fails,
and _because of that_ malloc (10000) fails, that would be "low quality
of implementation".
Mar 1 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
19
by: Hal Styli | last post by:
Hello, Can someone please help. I need to use a large array and I'm not sure when one should use (A) and when one should use (B) below:- #define MAX 10000000 (A) int x;
36
by: Martin Andert | last post by:
Hello, I have a question regarding malloc and free. Here my code sample: int main() { /* allocating dynamic memory for array */ int* array = (int*) malloc(5 * sizeof(int)); /* ... program...
54
by: Neo | last post by:
Hi Folks, I've a simple qestion related to dynamic memory allocation in C here is the code: #include <stdio.h> int main() {
35
by: ytrama | last post by:
Hi, I have read in one of old posting that don't cast of pointer which is returned by the malloc. I would like to know the reason. Thanks in advance, YTR
41
by: jacob navia | last post by:
In the C tutorial for lcc-win32, I have a small chapter about a debugging implementation of malloc. Here is the code, and the explanations that go with it. I would appreciate your feedback...
40
by: ramu | last post by:
Hi, what happens when i run the below code? main() { int *p; while(1) p= (int *)malloc(1000); } Do i get segmentation fault?
82
by: quiberon2 | last post by:
Hi, Sorry if it might be a stupid question but what should returns malloc(0) ? void *ptr = malloc(0); I am running gcc 3.3.5 and a non-null address is returned. ( in the compiler that I am...
3
by: Petr Pavlu | last post by:
Hello, I have two questions how the functions should be written. I read the FAQ but didn't find any answer. If there is any please point me out. I. Cleanup code Consider I have to open file1,...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.