Iam getting memory access violation error in VC
-
Hai, can anyone tell me what is the real problem in implementing malloc here bmpsrc = (U8 *) malloc(bmpsize); memset(bmpsrc, 0xff, 5); Thanks Harshadha
What is
U8
? What is value ofbmpsize
?Prasad Notifier using ATL | Operator new[],delete[][^]
-
Hai, can anyone tell me what is the real problem in implementing malloc here bmpsrc = (U8 *) malloc(bmpsize); memset(bmpsrc, 0xff, 5); Thanks Harshadha
-
You should probably check that bmpsrc != NULL - your memory allocation could fail if there's not enough memory (or if there isn't a single chunk of memory big enough for the allocation)
void example() { U32 bmpsize; //this is an integer datatype U8 *bmpsrc=0x00FC0; //this is the character datatype //i want to use malloc only ..... bmpsrc =malloc(bmpsize); memset(bmpsrc, 0x00FC0, 0); .. .. .. } this is my actual coding ..... i dont know how to change its memory allocation Harshadha
-
What does your debugger tell you?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
What is
U8
? What is value ofbmpsize
?Prasad Notifier using ATL | Operator new[],delete[][^]
void example() { U32 bmpsize; //this is an integer datatype U8 *bmpsrc=0x00FC0; //this is the character datatype //i want to use malloc only ..... bmpsrc =malloc(bmpsize); memset(bmpsrc, 0x00FC0, 0); .. .. .. } this is my actual coding ..... i dont know how to change its memory allocation
-
void example() { U32 bmpsize; //this is an integer datatype U8 *bmpsrc=0x00FC0; //this is the character datatype //i want to use malloc only ..... bmpsrc =malloc(bmpsize); memset(bmpsrc, 0x00FC0, 0); .. .. .. } this is my actual coding ..... i dont know how to change its memory allocation
harshadha wrote:
bmpsrc =malloc(bmpsize);
What is value of
bmpsize
?harshadha wrote:
memset(bmpsrc, 0x00FC0, 0);
Why you are passing last parameter as 0, it should be less than or equal to
bmpsize
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
The instruction at "0x006aoef8" referenced memory at "ox00000000".The memory could not be read.
That's not a text from your debugger. That's Windows error message. By using the debugger you have, you can set a break point in your source code. When the program reaches the break point, the debugger will stop the execution of youe program so you can (amongst other things) inspect your variables and find out the cause of the problem. You should learn how to use the debugger. It's not very hard to do and the debugger will definately save you heaps of time when you are looging for problems with your code.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
That's not a text from your debugger. That's Windows error message. By using the debugger you have, you can set a break point in your source code. When the program reaches the break point, the debugger will stop the execution of youe program so you can (amongst other things) inspect your variables and find out the cause of the problem. You should learn how to use the debugger. It's not very hard to do and the debugger will definately save you heaps of time when you are looging for problems with your code.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
harshadha wrote:
bmpsrc =malloc(bmpsize);
What is value of
bmpsize
?harshadha wrote:
memset(bmpsrc, 0x00FC0, 0);
Why you are passing last parameter as 0, it should be less than or equal to
bmpsize
.Prasad Notifier using ATL | Operator new[],delete[][^]
the bmpsize value is taken equal to the data type value(U32 bmpsize that is),it is taken as 2bytes. My real problem is i want to create a buffer to draw a bmp file... for that i have to use malloc then i need bmpsrc that is the memory allocated area and the size.....
-
the bmpsize value is taken equal to the data type value(U32 bmpsize that is),it is taken as 2bytes. My real problem is i want to create a buffer to draw a bmp file... for that i have to use malloc then i need bmpsrc that is the memory allocated area and the size.....
harshadha wrote:
the bmpsize value is taken equal to the data type value(U32 bmpsize that is),it is taken as 2bytes.
In this case, third parameter to memset in your OP should be
bmpsize
. Where as in your OP, you was passing 5, that was causing problem.harshadha wrote:
i have to use malloc then i need bmpsrc that is the memory allocated area and the size.....
May be you can be little clear, what you are trying to say.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
void example() { U32 bmpsize; //this is an integer datatype U8 *bmpsrc=0x00FC0; //this is the character datatype //i want to use malloc only ..... bmpsrc =malloc(bmpsize); memset(bmpsrc, 0x00FC0, 0); .. .. .. } this is my actual coding ..... i dont know how to change its memory allocation Harshadha
I think you've got your initial variable setup the wrong way round. bmpsize doesn't seem to have a value, and you're setting the value of your pointer to 0x00fc0, which I guess is meant to be the actual size. If that's the case, you've also got the second and third arguments of memset the wrong way around. I hope you'll remember to free that pointer when you're done with it.