Problem With Structure

H

Harry

Good Day,

Here is a structure that i am using in my code

typedef struct storable_picture
{

PictureStructure structure;

int poc;
int top_poc;
int bottom_poc;
int frame_poc;
int order_num;
int ref_pic_num[6*MAXLISTSIZE];
int frm_ref_pic_num[6*MAXLISTSIZE];
int top_ref_pic_num[6*MAXLISTSIZE];
int bottom_ref_pic_num[6*MAXLISTSIZE];
unsigned frame_num;
int pic_num;
int long_term_pic_num;
int long_term_frame_idx;

int is_long_term;
int used_for_reference;
int is_output;
int non_existing;

int size_x, size_y, size_x_cr, size_y_cr;
int chroma_vector_adjustment;
int coded_frame;
int MbaffFrameFlag;

unsigned short imgY[176*144];
unsigned short imgUV[2*88*72];
unsigned char mb_field[99];

char ref_idx[2*36*44];
int ref_pic_id[6*36*44];
int ref_id[6*36*44];
short mv[2*44*36*2];
unsigned char moving_block[44*36];
unsigned char field_frame[44*36];

struct storable_picture *top_field;
struct storable_picture *bottom_field;
struct storable_picture *frame;

int chroma_format_idc;
int frame_mbs_only_flag;

} StorablePicture;


The above structure is in a header file.In another c file in the
project,i am using the following statements in a function(I have
included the header file where the structure is declared)

StorablePicture *s;
s = calloc (1,sizeof(StorablePicture));

I kept a breakpoint at the second line and when i compile,the compiler
is not reporting an error.when i run the code,an unhandled exception
occurs at the place where memory is allocated for the structure using
calloc.Where is the problem?Help me out.....
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Harry said:
I didn't get u...do u want the code

Don't top post.

He is saying the problem is elsewhere, not in any of the two
lines you posted.
(C is like that -- do something your're not supposed to one place, and
it might result in an error elsewhere)
 
H

Harry

Nils said:
Don't top post.

He is saying the problem is elsewhere, not in any of the two
lines you posted.
(C is like that -- do something your're not supposed to one place, and
it might result in an error elsewhere)



ok...leave the code...actually i am getting an unhandled
exception..access viloation when i am using calloc....what solution is
there for the problem
 
T

T.M. Sommers

Harry said:
ok...leave the code...actually i am getting an unhandled
exception..access viloation when i am using calloc....what solution is
there for the problem

If you are getting an exception, it sounds like you are using
C++, so the first thing you should do is go to comp.lang.c++.
 
R

Richard Bos

Harry said:
ok...leave the code...actually i am getting an unhandled
exception..access viloation when i am using calloc....what solution is
there for the problem

The solution is to go over all your allocation and pointer handling code
to make sure you don't scribble through a wild pointer, or over the ends
of your allocated memory, somewhere. You have probably corrupted your
allocation data somewhere else in your program, and that _this_ calloc()
call crashes is probably merely a symptom of a real bug perpetrated some
time before.

Richard
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Harry said:
ok...leave the code...actually i am getting an unhandled
exception..access viloation when i am using calloc....what solution is
there for the problem
The solution is to fix the problem.

Noone here can help you with that as you havn't posted your code.
Somewhere in your code, perhaps at a very unrelated place to where
you actually call calloc, you have an error.

As mentioned the problem is , very very likely, not at the point
where you call calloc.

AND - remember to include the stdlib.h headerfile when you use calloc.
 
H

Harry

Nils said:
The solution is to fix the problem.

Noone here can help you with that as you havn't posted your code.
Somewhere in your code, perhaps at a very unrelated place to where
you actually call calloc, you have an error.

As mentioned the problem is , very very likely, not at the point
where you call calloc.

AND - remember to include the stdlib.h headerfile when you use calloc.



i have included stdlib.h....ok i will solve the problem...thanks for
the responses...
 
J

jacob navia

You are making an error somewhere in your program, an error
in the fragile malloc/calloc/free system.

To avoid those problems and go on with you rapplication use
a garbage collector, i.e. the GC library from
Boehms. This will automatically collect uneeded memory
-with a few restrictions). The library automatically reclaims
unused memory, so you do not need free.

To solve your problem do the following:

1) replace all calls to free() with nothing, i.e.

#define free(a)

and see if the problem persists. If it does, you have some
memory overwrite somewhere. If it DOESN'T you have freed twice
something OR have a memory overwrite.

2) Look at memory overwrites, check the parameters being passed
to malloc and calloc. Use a program to verify the heap.

3) Use a debug version of malloc

jacob
 
J

jacob navia

T.M. Sommers said:
If you are getting an exception, it sounds like you are using C++, so
the first thing you should do is go to comp.lang.c++.

What?

An exception means the OS gets an interrupt from the program
because the program accesses wrong address. It has nothing
to do with C++ exceptions!
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

jacob said:
What?

An exception means the OS gets an interrupt from the program
because the program accesses wrong address. It has nothing
to do with C++ exceptions!

As such, this term is mostly used in the Windows world, not everyone
are aware of that - which easily leads to associating ''exceptions''
with C++.
 
A

Ancient_Hacker

what is MAX_LIST_SIZE? without knowing that, we can't estimate the
suize of this structure.


You're already asking for about 106,000 bytes for the rest of the
structure.

How many allocs work before it fails?
 
R

Richard Bos

jacob navia said:
You are making an error somewhere in your program, an error
in the fragile malloc/calloc/free system.

To avoid those problems and go on with you rapplication use
a garbage collector, i.e. the GC library from
Boehms.

FFS, jacob, do you really have to have _two_ hobby-horses to be
unbelievably tiresome and, not to put too fine a point on it, bloody
well _wrong_ about? Knock it off, boy.

(Oh, and BTW: learn to quote.)

Richard
 
T

T.M. Sommers

jacob said:
An exception means the OS gets an interrupt from the program
because the program accesses wrong address. It has nothing
to do with C++ exceptions!

The phrase 'unhandled exception' is typical C++ terminology. In
standard C, one ususlly talks about signals, not exceptions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top