|
rajneshmalik wrote: I done CString mydata=new CString[10][10];
Two dimension array cannot be created like this.
You have to do like
CString** pStr = new CString* [10];
for( int i = 0; i < 10; i++ )
pStr[i] = new CString[10];
- NS -
|
|
|
|
|
hi
first thank u to help me,my concept r not so clear because i m new for mfc but i want to describe my problem to u.
i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,i think u have to modefied ur statement.i am also getting memory leak problem.please reply soon thank u
malik
|
|
|
|
|
I CStringArray is enough for the purpose.
rajneshmalik wrote: i am also getting memory leak problem
May you are not calling delete in the proper way.
- NS -
|
|
|
|
|
rajneshmalik wrote: i want to allocate memory for two diamentional sring
try
typedef std::vector<CString> vecCString;
typedef std::vector<vecCString> vecTwoDimensionCString;
typedef std::vector<vecTwoDimensionCString> vecThreeDimensionCString;
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
While you probably should use an array class as others have mentioned,
you can create multi dimension arrays on the heap if you use the proper
syntax:
CString (*mydata)[10] = new CString[10][10];
...
delete[] mydata;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi
first thank u to help me,my concept r not so clear because i m new for mfc but i want to describe my problem to u.
i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,i think u have to modefied ur statement.i am also getting memory leak problem.please reply soon thank u
malik
|
|
|
|
|
rajneshmalik wrote: i have a directory that have unknown number of file i want to show and sort those file for this i want a CString type variable(object) so that i can show those file,
In that case I don't see why you need a multi-dimension array.
Directory listings are one-dimensional.
A CStringArray is an excellent choice IMO.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I view some code style like
<br />
if (CListCtrl::GetItemData() & 1)<br />
{<br />
}<br />
Anybody could explain clearly? thx first!
|
|
|
|
|
CListCtrl::GetItemData(),this function will return something and you r anding the return value with 1
bye...
|
|
|
|
|
I think like
<br />
if (GetStateKey(VK_SHIFT) & 0x8000)<br />
{<br />
}<br />
means press the SHIFT key down,
<br />
if (CListCtrl::GetItemData() & 1)<br />
{<br />
}<br /> must mean something specail. Anyone could help me understanding it ?
|
|
|
|
|
The '&' is a bitwise operator. It can be used for checking whether a specific bit is set or reset. For example, 10 & 1 means 1010 & 0001 in binary, the result will be zero since the first bit is zero. 0101 & 0001 will result in 1 because the the first bit is 1.
Similarly the data obtained from list control through GetItemData is being checked for first bit set or reset. All other bits are avoided. The if block will be executed only if the first bit of the obtained data is 1.
Hope you are clear about it now.
- NS -
|
|
|
|
|
What you said I've know before I post the question.
Then Let me tell you all my confusion. What returned from GetItemData is a WORD_PTR, Then I really don't understand what does GetItemData return?
I viewed some codes like this:
<br />
(MyDataStruct *) pData = (MyDataStruct *)GetItemData(iItem);<br />
I'm really confused.
|
|
|
|
|
The GetItemData API is returning the value, which is set by us using SetItemData API. So the meaning of "CListCtrl::GetItemData() & 1" is absolutely depends on the data you have set to the list control using the SetItemData.
- NS -
|
|
|
|
|
Your answer is exactly what I'm looking for. Thx hundred times. Use SetItemData first, then you can use GetItemData
|
|
|
|
|
fantasy1215 wrote: Use SetItemData first, then you can use GetItemData
Exactly...
|
|
|
|
|
Hi all,
I want to use a dynamic buffer in one of my application. I'll explain it in this way. Depend on one of my calculation I found a number(int value), and I want to define a buffer size to that value. Then after doing all the required process need to clear that buffer size and define it to the next calculated size. Simply it is looping.
So how can I do it.
Thanks,
I appreciate your help all the time...
Eranga
|
|
|
|
|
use malloc or new..
for eg. for char,
char *l_temp = (char*) malloc(value*sizeof(char));
if(temp==NULL)
return;
////Reqd code
//at last
free(l_temp);
|
|
|
|
|
Eranga Thennakoon wrote: Simply it is looping.
Is the memory bolck is of fixed size ? If yes, then allocate only once, and use it all the way.
Regards,
Paresh.
|
|
|
|
|
But in that way, I have to waist my resources. Because in some case(I mean in a single iteration) full buffer is not use.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Could you please explain the situation ?
Regards,
Paresh.
|
|
|
|
|
Sure, here it is.
Initially I've used a predefined buffer of size 5000 as follows.
char buffer[5000];
Then on my application I found that the length of a bytes stream and going to read it using the buffer. Sometimes the stream is too small, and in some cases it is too long. So I want to use a dynamic buffer to avoid wasting memory.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Try using realloc .
Regards,
Paresh.
|
|
|
|
|
hai,
iam not sure weather the following logic suits your application but you can try it.
1.at the start of your loop, as you are caluculating the length, allocate that many number of bytes.
2.use them however you want them.
3.at the end of the loop, release them i mean, de allocate (free) them.
as far as i know, once the loop ends, the memory allocated should automatically be freed.
good luck.
|
|
|
|
|
Sure, the thing I found difficult is that how to create a dynamic buffer. Now it is ok.
I appreciate your help all the time...
Eranga
|
|
|
|
|
What about...
void* pBuffer = NULL;
;
;
pBuffer = new BYTE [intSize];
;
;
delete [] pBuffer;
pBuffer = NULL;
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|