🔒 Locked
Pointer to Allocated Memory Problem
Advertisement
Original Post
Hi All
Im having some problems with memory allocation, and a pointer to its data.
I have my TGA loading function :
unsigned char *LoadTGA(char *filename);
This will load, and if succesful return the allocated image data or NULL on failure.
So I thought I would go do this:
unsigned char *p_data = LoadTGA("targa.tga");
Problem is, this doesn''t seem to be working, when I run my program I get an assertion error.
Also I tried allocating 1000 int''s in a console app, then passing it to a pointer, then deleting that pointer. However it wont delete the allocated data? :\
Any Idea''s? Plase Help
Thanks
unsigned char * const p_data = LoadTGA("targa.tga");
By making it a constant pointer, I hope that it won''t loose focus, if that''s what''s happening.
By making it a constant pointer, I hope that it won''t loose focus, if that''s what''s happening.
quote:
Original post by Mathematix
By making it a constant pointer, I hope that it won''t loose focus, if that''s what''s happening.
?
quote:
Original post by Anonymous Posterdelete[streamsize] p_data
That's not valid C++ code. Are you talking about another language?
[edited by - petewood on September 10, 2003 6:59:45 AM]
petewood: I don''t know what''s happening with the rest of the code, so am making the pointer point to the region of memory pointed to by the return value of LoadTGA() and only to that region.
I think you need to post the code contained in the function - you can't tell much from what you've posted.
Mathematix: As for making it a const - I'm not sure what you're trying to achieve either. That const declaration says that the pointer can't be assigned to anything else - If another bit of code is screwing around with memory it's not going to pay any attention to whether a pointer stored there is const or not.
[edited by - stubble on September 10, 2003 8:44:14 AM]
[edited by - stubble on September 10, 2003 8:44:46 AM]
Mathematix: As for making it a const - I'm not sure what you're trying to achieve either. That const declaration says that the pointer can't be assigned to anything else - If another bit of code is screwing around with memory it's not going to pay any attention to whether a pointer stored there is const or not.
[edited by - stubble on September 10, 2003 8:44:14 AM]
[edited by - stubble on September 10, 2003 8:44:46 AM]
quote:
Original post by stubble
Mathematix: As for making it a const - I'm not sure what you're trying to achieve either. That const declaration says that the pointer can't be assigned to anything else - If another bit of code is screwing around with memory it's not going to pay any attention to whether a pointer stored there is const or not.
I am aware of that, but it still makes for more robust code. Until it is known what the rest of the code is doing, as you clearly point out, there's nothing wrong with it.
quote:
Original post by stubble That const declaration says that the pointer can't be assigned to anything else.
You've just answered your own, as well as petewood's, question.
[edited by - mathematix on September 10, 2003 8:52:59 AM]
Oh ok - I was under the impression that the error occured on that line. Making it const is good practice though.
ugh?
[edited by - stubble on September 10, 2003 9:04:28 AM]
[edited by - stubble on September 10, 2003 9:06:24 AM]
quote:
You've just answered your own, as well as petewood's, question.
ugh?
[edited by - stubble on September 10, 2003 9:04:28 AM]
[edited by - stubble on September 10, 2003 9:06:24 AM]
quote:
Original post by Anonymous Poster
http://msdn.microsoft.com/library/en-us/vccelng/htm/express_31.asp?frame=true
And this shows... ?
[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people
quote:
Original post by stubble
Oh ok - I was under the impression that the error occured on that line. Making it const is good practice though.quote:
You''ve just answered your own, as well as petewood''s, question.
ugh?
[edited by - stubble on September 10, 2003 9:04:28 AM]
I fekking give up!
quote:
Original post by stubblequote:
I fekking give up!
Don''t stress.. My point was that I didn''t actually ask a question - so not sure how I could have answered it..
Oh! Okay... stress gone.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement