473,748 Members | 10,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calloc problem

I have the following code and I can not figure out
why Stg2In returns a null pointer?
"Stg2In = (float *)calloc(9*Data Len, sizeof(float)); "
while
"Stg2Out = (float *)calloc(9*Data Len, sizeof(float)); "
is sucessful?

Can anyone Help?

Thx
void IntepolatorFloa t(float *DataOut,float *DataIn,int DataLen)

{

int i,j;
float *Stg1In;
float *Stg1Out;
float *Stg2In;
float *Stg2Out;
float *Stg3In;
float *Stg3Out;
//1st stage
Stg1In = (float *)calloc(3*Data Len, sizeof(float));
Stg1Out = (float *)calloc(3*Data Len, sizeof(float));
//Insert 0
for(i=0;i<DataL en;i++){
Stg1In[3*i]=DataIn[i];
Stg1In[3*i+1]=0;
Stg1In[3*i+2]=0;
}
//Filtering
for(i=28;i<3*Da taLen;i++)
{
Stg1Out[i]=0.0000;
for(j=0;j<sizeo f(coeffFloat1)/4;j++){
Stg1Out[i]=Stg1Out[i]+coeffFloat1[j]*Stg1In[i-j];}

}

//End of First Stage

//Begin of stage 2
Stg2In = (float *)calloc(9*Data Len, sizeof(float));
Stg2Out = (float *)calloc(9*Data Len, sizeof(float));
//Insert 0
for(i=0;i<3*Dat aLen;i++){
Stg2In[3*i]=Stg1Out[i];
Stg2In[3*i+1]=0.0;
Stg2In[3*i+2]=0.0;
}
//Filtering
for(i=20;i<9*Da taLen;i++)
{
for(j=0;j<sizeo f(coeffFloat2)/4;j++){
Stg2Out[i]=Stg2Out[i]+coeffFloat2[j]*Stg2In[i-j];}

}
//end of Stage 2

//Begin of stage 3
Stg3In = (float *)calloc(18*Dat aLen, sizeof(float));
Stg3Out = (float *)calloc(18*Dat aLen, sizeof(float));
//Insert 0
for(i=0;i<9*Dat aLen;i++){
Stg3In[2*i]=Stg2Out[i];
Stg3In[2*i+1]=0;
}
//Filtering
for(i=10;i<18*D ataLen;i++)
{

for(j=0;j<sizeo f(coeffFloat3)/4;j++){
DataOut[i]=DataOut[i]+coeffFloat3[j]*Stg3In[i-j];}
DataOut[i]=DataOut[i];
}
//end of Stage 3
free(Stg1In);
free(Stg1Out);
free(Stg2In);
free(Stg2Out);
free(Stg3In);
free(Stg3Out);
}

Nov 15 '05 #1
2 1748

<ch********@yah oo.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I have the following code and I can not figure out
why Stg2In returns a null pointer?
"Stg2In = (float *)calloc(9*Data Len, sizeof(float)); "
while
"Stg2Out = (float *)calloc(9*Data Len, sizeof(float)); "
is sucessful?

Can anyone Help?


1. Did you #include <stdlib.h>?

2. Don't cast the return value from 'calloc()'

3. Have you checked the return value from *every*
call to 'calloc()'?

-Mike
Nov 15 '05 #2
Mike Wahler wrote
(in article
<cC************ ***@newsread3.n ews.pas.earthli nk.net>):

<ch********@yah oo.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I have the following code and I can not figure out
why Stg2In returns a null pointer?
"Stg2In = (float *)calloc(9*Data Len, sizeof(float)); "
while
"Stg2Out = (float *)calloc(9*Data Len, sizeof(float)); "
is sucessful?

Can anyone Help?


1. Did you #include <stdlib.h>?

2. Don't cast the return value from 'calloc()'

3. Have you checked the return value from *every*
call to 'calloc()'?


4. Are you *sure* you want to use calloc() with floats?

5. why use float instead of double anyway?
--
Randy Howard (2reply remove FOOBAR)

Nov 15 '05 #3

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

Similar topics

26
6759
by: dagger | last post by:
Hi there. I'm using C under FreeBSD with the gcc compiler and am having a bit of trouble using the calloc and realloc calls. As an example the code snippet: #include <stdio.h> int main() { char *ptr;
16
8994
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those who don't speak french arbre means tree.
14
6526
by: Rahul Gandhi | last post by:
Which one is more fast? malloc followed by memset or calloc
27
4764
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning: assignment makes pointer from integer without a cast ================================================================== when the following piece of code was compiled. The offending statement is calloc. A similar statement in the main() function...
40
2528
by: boris | last post by:
Hi! I'm seeking some answers about what seems to be a memory leak. I have a loop that looks much like this: double *largeArray = (double*) calloc(); for (...) { printf("iteration #...\n"); for (...) { double *foo = (double*) calloc();
11
5797
by: lohith.matad | last post by:
Hi all, Though the purpose of both malloc() and calloc() is the same, and as we also know that calloc() initializes the alloacted locations to 'zero', and also that malloc() is used for bytes allocation whereas calloc() for chunk of memory allocation. Apart from these is there any strong reason that malloc() is prefered over calloc() or vice-versa? Looking forward for your clarrifications , possibly detailed.
7
2175
by: mef526 | last post by:
I have had this problem for months now and it has been nagging me. I have a large project that has several C++ DLL's, one of them uses malloc / calloc / free for the other DLL's. I process very large datafiles (100MB to 300 MB) that have more than 524,000 lines with 5 columns of numbers in text. I allocate 8 arrays with 524,000 or more doubles , and 10 arrays of 32,768 doubles. Is there a min size for malloc / calloc required to...
3
2113
by: Alexander Behnke | last post by:
Hello, I am currently facing a problem with a calloc function call which returns a NULL pointer while in a debugging environment. If I start the same executable from the shell (not via the debugger) a valid pointer is returned. The call stack looks like this: FlowPRESS.exe!strcat() Line 169 Asm
7
3764
by: ds | last post by:
Hello all, I have a problem with calloc I have never seen before. I am migrating some C code to C++ and at some part in the C code there is a calloc that creates an array of structures. Now in the C++ version, the structures are classes with virtual access functions. I am working on linux with g++ and it seems that the _vptr part of the class is null. Further use of these classes causes a segmentation fault. Of course if I use new...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.