Skip to main content
gamedev.net
🔒 Locked

Pointer to Allocated Memory Problem

Started by Shock 12 replies 850+ views
Original Post
Shock
Shock
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
Mathematix
Mathematix
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.
Qw3r7yU10p!
Qw3r7yU10p!
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.


?
Qw3r7yU10p!
Qw3r7yU10p!
quote:
Original post by Anonymous Poster
delete[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]
Mathematix
Mathematix
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.
stubble
stubble
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
Mathematix
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]
stubble
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]

[edited by - stubble on September 10, 2003 9:06:24 AM]
Mathematix
Mathematix
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!

stubble
stubble
quote:
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..
Mathematix
Mathematix
quote:
Original post by stubble
quote:
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.