![]() |
|
#1
|
|||
|
|||
pointer/memory issueHi, I have an issue with the following piece of code, in it I read a node from a binary file, and return it.
CPP / C++ / C Code:
this works fine, but I will call this operation many times, so I think doing this loop CPP / C++ / C Code:
So I was thinking, maybe instead of returning the node, better to pass it to the function (do the for loop outside), and it just gets rewritten every time I use it. The problem is that I tried it, but it didn't work, and as I am storing those read values somewhere else, it just becomes a mess, and only keeps the last value that was read. this was my idea, that didn't work: CPP / C++ / C Code:
I guess it has to do with some pointer management, but not sure how to fix it. I'd appreciate any insight and help with it. Thanks |
|||
|
#2
|
|||
|
|||
Re: pointer/memory issueSince the class for which m_pDims is an object has a push_back() function and overloaded [], maybe it has resize(). (Like a std::vector, for example). If it does, then maybe the loop could be replaced by
CPP / C++ / C Code:
(I am assuming that the vector has size = 0 when this function is invoked, otherwise the resize argument would be p->m_pDims.size() + m_maxDim, since your loop appends that m_maxDim elements to whatever the present vector is.) (I'm assuming that m_maxDim is not constant for a given object of this class; otherwise you would have fixed the size in the constructor, right?) (I'm also assuming that you really need a vector, since if you aren't actually using m_pDims as a vector ---that is, you are always accessing it with [] notation rather than pushing and popping and you always know its size--- then you would have made it an array rather than a vector, right?) Regards, Dave |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to issue dos command from c program | jaininaveen | C Programming Language | 2 | 03-Mar-2006 11:02 |
| Computer resets - weird memory slot issue | SpikeyUK | Computer Hardware Forum | 7 | 22-Jul-2005 19:15 |
| PHP/MySQL coding issue | cmarti | MySQL / PHP Forum | 3 | 26-Jul-2004 09:01 |
| PHP/Apache memory usage issue | bacchus | Apache Web Server Forum | 0 | 18-Aug-2003 13:57 |
| Possible issue with HTML BBCode? | JdS | GIDForums™ | 2 | 16-Aug-2003 12:14 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The