|
It works fine when the height and width are equal or if the height is less than width
The error occurs only when the height is greater than the width.
BoundsChecker displays an error message "Dynamic memory overrun"
|
|
|
|
|
Hello.
See my earlier post. You allocate <width> no of items twice.
You don't use <height>, except in the allocating loop.
Since you allocate room for <width> items in your table.
So it's natural that you go out of bounds if height is bigger than what you allocated (which is <height> items).
Kakan
|
|
|
|
|
so how should I allocate and delete dynamic memory when the width and height are different.
help me with some code.
|
|
|
|
|
Sorry, I'm at work and have work to do.
But there is HEAPS of source code for dynamic 2-dimensional arrays out there.
Serach at CodeProject and/or Google.
I think you need to find a working example to start with.
Good luck.
Kakan.
|
|
|
|
|
Hello again. I couldn't let go of your problem.
I found a lot of suggestions at experts exhange, at:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21442835.html[^]
This example looks interesting, and complete:
<br />
template < typename T ><br />
T **Allocate2DArray( int nRows, int nCols)<br />
{<br />
T **ppi;<br />
T *pool;<br />
T *curPtr;<br />
<br />
ppi = new T*[nRows];<br />
<br />
pool = new T [nRows * nCols];<br />
<br />
curPtr = pool;<br />
for( int i = 0; i < nRows; i++)<br />
{<br />
*(ppi + i) = curPtr;<br />
curPtr += nCols;<br />
}<br />
return ppi;<br />
}<br />
<br />
template < typename T ><br />
void Free2DArray(T** Array)<br />
{<br />
delete [] *Array;<br />
delete [] Array;<br />
}<br />
<br />
int main()<br />
{<br />
double **d = Allocate2DArray<double>(10000, 10000);<br />
d[0][0] = 10.0;<br />
d[1][1] = 20.0;<br />
d[9999][9999] = 2345.09;<br />
Free2DArray(d);<br />
}<br />
In the main function, you can see how to use the array.
I think you should try it out.
Regards
Kakan
|
|
|
|
|
Arrun wrote: ImagePro = new double*[width];
for(int i = 0; i < height; i++)
If you allocate room for width double pointers, it only makes sense that the for loop execute only that many times. If height happens to be larger than width , an error should be expected. See here for an example.
Arrun wrote: for(int i = 0; i < height; i++)
{
delete ImagePro[i];
}
delete ImagePro;
Change to:
for(int i = 0; i < height; i++)
delete [] ImagePro[i];
delete [] ImagePro;
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
When I try to insert line numbers into my CRichEditView application, it only displays numbers upto 255. When the document has more than 255 lines, number 255 get repeated.
Can anybody let me know how to fix this?
Here's my code
PARAFORMAT2 pf = GetParaFormatSelection();
pf.cbSize = sizeof(pf);
pf.dwMask = PFM_NUMBERING | PFM_STARTINDENT | PFM_NUMBERINGSTART | PFM_NUMBERINGSTYLE;
pf.wNumbering = 2;
pf.wNumberingStart = 1;
pf.wNumberingStyle = 0x200;
pf.dxStartIndent = 10;
SetParaFormat(pf);
It's like this, if i start numbering with 100 it is repeating after 354. Number range is limited to 255 numbers. Can we set the number range in PARAFORMAT2 structure?
Thanks
|
|
|
|
|
The problem is that you are using something for which it was not designed.
The Numbering feature of the Rich Edit controls is not to be used for showing line numbers like how a fancy text editor does in its margin, it is used to format a paragraph into a numbered (or bulleted) list.
My guess is that the 255 item limit is due to the design of the feature.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Is that so
Then how can I display line numbers in my document? My view class is derived from CRichEditView.
Any suggestions?
Thanks for da reply
sandakith
|
|
|
|
|
There are a few ways to do it. First, you could manually draw line numbers into the selection margin (or a shorten the width of the control). If you are dealing with a read-only document (read-only as far as the user is concerned), you could manually insert line numbers before the document is rendered.
Or you could use a control like Scintilla or the "Crystal editor", which both support line numbers natively, I believe. Projects/Articles exist that demonstrate both, I believe (search for 'em).
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
default protocol of web-site is http://
are there other protocols for web-files?
if yes, could you give me an sample and a link (web address which does not start with http://)
thx
includeh10
|
|
|
|
|
includeh10 wrote: default protocol of web-site is http://
are there other protocols for web-files?
Yes Default protocol is HTTP:// but you can also use https:// to access file tooo
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
includeh10 wrote: if yes, could you give me an sample and a link (web address which does not start with http://)
Gopher or FTP
Developed at the UofM (University of Minnesota) it as memory serves predates (slightly) http. The last (UofM) gopher website was taken down about a year ago.
Wiki link
Gopher_protocol[^]
There are a few other protocals but http dominates.
DEBUGGING : Removing the needles from the haystack.
-- modified at 6:09 Wednesday 9th November, 2005
|
|
|
|
|
do all web-sites support Http connection?
i.e. code bellow
//============================
CInternetSession sess;
......
CHttpConnection*pHttp=sess.GetHttpConnection(...);
//============================
can be applied to all web-sites?
if not, why not?
thx.
includeh10
|
|
|
|
|
includeh10 wrote: can be applied to all web-sites?
Yes, Just have a try!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi! People!
Anybody knows how to hide toolbar, menubar, controlbar and statusbar?
Can I use ShowWindow to hide this items and what other ways can I use.
Thanks for the help.
|
|
|
|
|
You can use ShowWindow with any window handle, but what window do you need to hide these items?
|
|
|
|
|
I have trouble displaying text that is in shift-jis, is there something special that i have to do to display it correctly?
Also is it possible to display an unsigned char into a textbox without casting it as a char?
|
|
|
|
|
Hi. This is not a Visual C++ question. Also, it'd be great if it worked under ANSI C.
In this function I'm writing, strings start to come up and need to be saved on a big char* one next to the other, say:
"yellow", "one", "banana" -> "yellowonebanana"
thing is that final length is unknown, it could be 1000b as well as it could be 0b. so I looked it up from Google and only solution found was to do the algorythm twice, where in the first one I calculate length, then malloc, then do again and start storing.
Is there any way to allocate and resize allocation dynamically?
Thx in advance. Mariano Lopez-Gappa.
|
|
|
|
|
|
realloc works just fine. However, it is best if you use some type of doubling algorithm on the buffer size. Thus you reduce the number of reallocations.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
You could create a file on the local drive and store as much as the drive would hold. There would be no need for any memory allocation or re-allocation. If you don't need speed, its an option.
|
|
|
|
|
Many thanks to all 3 answers. I'm gonna go for the realloc as it looks like it fits best my needs. Speed is not really an issue but I can't use disk. Thanks again. Case closed.
|
|
|
|
|
Can't you do this:
1. Read in the string to a temporary max-length memory location.
2. Allocate the strings' memory using the strlen() function.
3. Use strcpy() to move the string into it's position
4. Repeat steps 1-3 until you are done
5. Deallocate the temporary string.
That's the easiest way I can I see doing it straight-forward and using only ANSI-C commands.
|
|
|
|
|
Mariano Lopez-Gappa wrote: thing is that final length is unknown, it could be 1000b as well as it could be 0b.
Is that the only difference? Memory is cheap these days. Unless you are talking about several MB of allocations, just allocate 1KB for each instance and be done with it. Yes, there might be some waste here and there, but that's a whole lot more efficient than reallocating memory.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|