473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Rallocating a struct * *

Hello..!

I have this problem:
Following shows allocation of my struct:

///////////////////////////////////////////
FOO **foo;//this is my struct
FOO **reallocfoo;//this is an extra pointer

foo=(FOO **)malloc(StartNumber*sizeof(FOO*));
for(int c=0;c<StartNumber;c++)
{
ILChild[c]=new ImageLocaterData;
}
....
foo[Number]=...
....

///////////////////////////////////////////

This works well...!

Then I want to Realloc som more space for my foo.
Strangely I can only allocate space for my pointer 44 times...!!?

Following shows the code to realloc:

///////////////////////////////////////////

reallocfoo=(FOO**)realloc(foo,(StartNumber+(Reallo cInc*(Counter+1)))*sizeof(FOO*));
for(int c=StartNumber+(ReallocInc*Counter)-1;c<StartNumber+(ReallocInc*(Counter+1));c++)
{
reallocfoo[c]=new FOO;
}
foo=reallocfoo;
Counter+=1;

///////////////////////////////////////////

44 times that dosn't make sense...

Please help or I'll just keep writing :) - or something...

Regards Henrik Tomra
Nov 13 '05 #1
2 1130
Greetings.

In article <d1**************************@posting.google.com >, Henrik J
wrote:
I have this problem:
Following shows allocation of my struct:

///////////////////////////////////////////
FOO **foo;//this is my struct
FOO **reallocfoo;//this is an extra pointer

foo=(FOO **)malloc(StartNumber*sizeof(FOO*));
for(int c=0;c<StartNumber;c++)
{
ILChild[c]=new ImageLocaterData;
}
...
foo[Number]=...
...

///////////////////////////////////////////

This works well...!


On the contrary; this does not work at all. There is no "new" keyword in C,
and for a number of good reasons the result of malloc oughtn't be cast.

I suspect you're trying to write C++ code, not C, in which case you should
post this query to comp.lang.c++.

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Nov 13 '05 #2
On Fri, 07 Nov 2003 06:50:35 -0800, Henrik J wrote:
Hello..!

I have this problem:
Following shows allocation of my struct:
C++ code snipped
44 times that dosn't make sense...


After converting your code to C, I was able to realloc 45
times. If your intention is to write C (and not C++), then
try to post a minimal complete (compilable!) program that
demonstrates your problem. Then we'll be better able to help
you out.

-Sheldon

Nov 13 '05 #3

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

Similar topics

5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
5
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used...
19
by: Russell Shaw | last post by:
Hi, I have two structs in a header file, and they reference each other, causing a compile error. Is there a standard way to deal with this? typedef struct { ... RtAction *actions; }...
16
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
5
by: Johs32 | last post by:
I have a struct "my_struct" and a function that as argument takes a pointer to this struct: struct my_struct{ struct my_struct *new; }; void my_func(struct my_struct *new); I have read...
7
by: Alex | last post by:
If I have two struct. See below: struct s1 { int type; int (*destroy)(struct s1* p); } struct s2 { struct s1 base;
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
4
by: hugo.arregui | last post by:
Hi! I have two struts like that: struct { int num; int num2; struct b arrayOfB; } a;
4
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.