From: Mikel on 2 Oct 2009 09:26 Is it over a minute in Release mode or in Debug mode? Anyway, for such a long buffer, I think you should set the size of the destination string before starting to add elements. Otherwise, the string will have to reallocate the memory as it grows, which can take a lot of time. Try something like this: CString CipStr; CipStr.SetSize(buffer.GetSize()); for (i=0; i<buffer.GetSize(); i++) { if (buffer[i] == 0x00) buffer[i] = 0x01; CipStr.SetAtGrow(i, buffer[i]); // You could use CipStr[i] = buffer [i] or CipStr.SetAt(i, buffer[i]), but just in case... } Besides, take into account that you are changing the data in the original buffer, and maybe that's no what you want... On 2 oct, 14:23, "Eddards" <edda...(a)verizon.net> wrote: > This is what I have. > The size of the file read into buffer was 4.6mb > Why does it take so long to run through? (over a minute). > > int i; > CString CipStr; > for (i=0; i<buffer.GetSize(); i++){ > if (buffer[i] == 0x00) > buffer[i] = 0x01; > CipStr += buffer[i]; > } > > "Eddards" <edda...(a)verizon.net> wrote in message > > news:KpidnfDBIMVReljXnZ2dnUVZ_uOdnZ2d(a)giganews.com... > > > > >I tried copying the buffer with a loop like you show below. > > It took over a minute to process all 4,000,000 bytes. > > Dont know why it should take so long. > > > "Joseph M. Newcomer" <newco...(a)flounder.com> wrote in message > >news:57sac5hc63e673ijs0fdttud2annvadrno(a)4ax.com... > >> for(int i = 0; i < buffer.GetSize(); i++) > >> if(buffer[i] == 0x00) > >> buffer[i] = 0x01; > > >> What is so hard about this? This is pretty elementary C programming! > > >> If you want to do it more along the "hard way" read about the > >> MultiByteToWideChar API (and > >> see my essay on my MVP Tips site on CString techniques) > > >> joe > >> On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <edda...(a)verizon.net> wrote: > > >>>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to > >>>the > >>>CString > >>>Is this possible ? > > >>>"Eddards" <edda...(a)verizon.net> wrote in message > >>>news:9fGdnWZaLPg3J1nXnZ2dnUVZ_u6dnZ2d(a)giganews.com... > >>>>I am using VC6. > >>>> Is there a way to copy a CByteArray to a CString? > > >> Joseph M. Newcomer [MVP] > >> email: newco...(a)flounder.com > >> Web:http://www.flounder.com > >> MVP Tips:http://www.flounder.com/mvp_tips.htm- Ocultar texto de la cita - > > - Mostrar texto de la cita -
From: Eddards on 2 Oct 2009 09:35 Compiler error: error C2039: 'SetSize' : is not a member of 'CString' "Mikel" <mikel.luri(a)gmail.com> wrote in message news:f6b09929-7949-478a-a434-324702efa30c(a)j4g2000yqa.googlegroups.com... Is it over a minute in Release mode or in Debug mode? Anyway, for such a long buffer, I think you should set the size of the destination string before starting to add elements. Otherwise, the string will have to reallocate the memory as it grows, which can take a lot of time. Try something like this: CString CipStr; CipStr.SetSize(buffer.GetSize()); for (i=0; i<buffer.GetSize(); i++) { if (buffer[i] == 0x00) buffer[i] = 0x01; CipStr.SetAtGrow(i, buffer[i]); // You could use CipStr[i] = buffer [i] or CipStr.SetAt(i, buffer[i]), but just in case... } Besides, take into account that you are changing the data in the original buffer, and maybe that's no what you want... On 2 oct, 14:23, "Eddards" <edda...(a)verizon.net> wrote: > This is what I have. > The size of the file read into buffer was 4.6mb > Why does it take so long to run through? (over a minute). > > int i; > CString CipStr; > for (i=0; i<buffer.GetSize(); i++){ > if (buffer[i] == 0x00) > buffer[i] = 0x01; > CipStr += buffer[i]; > } > > "Eddards" <edda...(a)verizon.net> wrote in message > > news:KpidnfDBIMVReljXnZ2dnUVZ_uOdnZ2d(a)giganews.com... > > > > >I tried copying the buffer with a loop like you show below. > > It took over a minute to process all 4,000,000 bytes. > > Dont know why it should take so long. > > > "Joseph M. Newcomer" <newco...(a)flounder.com> wrote in message > >news:57sac5hc63e673ijs0fdttud2annvadrno(a)4ax.com... > >> for(int i = 0; i < buffer.GetSize(); i++) > >> if(buffer[i] == 0x00) > >> buffer[i] = 0x01; > > >> What is so hard about this? This is pretty elementary C programming! > > >> If you want to do it more along the "hard way" read about the > >> MultiByteToWideChar API (and > >> see my essay on my MVP Tips site on CString techniques) > > >> joe > >> On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <edda...(a)verizon.net> > >> wrote: > > >>>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to > >>>the > >>>CString > >>>Is this possible ? > > >>>"Eddards" <edda...(a)verizon.net> wrote in message > >>>news:9fGdnWZaLPg3J1nXnZ2dnUVZ_u6dnZ2d(a)giganews.com... > >>>>I am using VC6. > >>>> Is there a way to copy a CByteArray to a CString? > > >> Joseph M. Newcomer [MVP] > >> email: newco...(a)flounder.com > >> Web:http://www.flounder.com > >> MVP Tips:http://www.flounder.com/mvp_tips.htm- Ocultar texto de la > >> cita - > > - Mostrar texto de la cita -
From: Mikel on 2 Oct 2009 10:19 On 2 oct, 15:35, "Eddards" <edda...(a)verizon.net> wrote: > Compiler error: > error C2039: 'SetSize' : is not a member of 'CString' > > "Mikel" <mikel.l...(a)gmail.com> wrote in message > > news:f6b09929-7949-478a-a434-324702efa30c(a)j4g2000yqa.googlegroups.com... > Is it over a minute in Release mode or in Debug mode? > Anyway, for such a long buffer, I think you should set the size of the > destination string before starting to add elements. Otherwise, the > string will have to reallocate the memory as it grows, which can take > a lot of time. > > Try something like this: > > CString CipStr; > CipStr.SetSize(buffer.GetSize()); > > for (i=0; i<buffer.GetSize(); i++) > { > if (buffer[i] == 0x00) > buffer[i] = 0x01; > CipStr.SetAtGrow(i, buffer[i]); // You could use CipStr[i] = buffer > [i] or CipStr.SetAt(i, buffer[i]), but just in case... > > } > > Besides, take into account that you are changing the data in the > original buffer, and maybe that's no what you want... > > On 2 oct, 14:23, "Eddards" <edda...(a)verizon.net> wrote: > > > > > This is what I have. > > The size of the file read into buffer was 4.6mb > > Why does it take so long to run through? (over a minute). > > > int i; > > CString CipStr; > > for (i=0; i<buffer.GetSize(); i++){ > > if (buffer[i] == 0x00) > > buffer[i] = 0x01; > > CipStr += buffer[i]; > > } > > > "Eddards" <edda...(a)verizon.net> wrote in message > > >news:KpidnfDBIMVReljXnZ2dnUVZ_uOdnZ2d(a)giganews.com... > > > >I tried copying the buffer with a loop like you show below. > > > It took over a minute to process all 4,000,000 bytes. > > > Dont know why it should take so long. > > > > "Joseph M. Newcomer" <newco...(a)flounder.com> wrote in message > > >news:57sac5hc63e673ijs0fdttud2annvadrno(a)4ax.com... > > >> for(int i = 0; i < buffer.GetSize(); i++) > > >> if(buffer[i] == 0x00) > > >> buffer[i] = 0x01; > > > >> What is so hard about this? This is pretty elementary C programming! > > > >> If you want to do it more along the "hard way" read about the > > >> MultiByteToWideChar API (and > > >> see my essay on my MVP Tips site on CString techniques) > > > >> joe > > >> On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <edda...(a)verizon.net> > > >> wrote: > > > >>>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to > > >>>the > > >>>CString > > >>>Is this possible ? > > > >>>"Eddards" <edda...(a)verizon.net> wrote in message > > >>>news:9fGdnWZaLPg3J1nXnZ2dnUVZ_u6dnZ2d(a)giganews.com... > > >>>>I am using VC6. > > >>>> Is there a way to copy a CByteArray to a CString? > > > >> Joseph M. Newcomer [MVP] > > >> email: newco...(a)flounder.com > > >> Web:http://www.flounder.com > > >> MVP Tips:http://www.flounder.com/mvp_tips.htm-Ocultar texto de la > > >> cita - > > > - Mostrar texto de la cita -- Ocultar texto de la cita - > > - Mostrar texto de la cita - Yes, sorry. SetSize is not present in CString. It's a CArray thing. You can use GetBuffer or GetBufferSetLength instead. Anyway, you have to allocate memory for the string before adding characters.
From: Tom Serface on 2 Oct 2009 11:00 Oops sorry, didn't mean to dup you answer. Tom "Mikel" <mikel.luri(a)gmail.com> wrote in message news:f6b09929-7949-478a-a434-324702efa30c(a)j4g2000yqa.googlegroups.com... Is it over a minute in Release mode or in Debug mode? Anyway, for such a long buffer, I think you should set the size of the destination string before starting to add elements. Otherwise, the string will have to reallocate the memory as it grows, which can take a lot of time. Try something like this: CString CipStr; CipStr.SetSize(buffer.GetSize()); for (i=0; i<buffer.GetSize(); i++) { if (buffer[i] == 0x00) buffer[i] = 0x01; CipStr.SetAtGrow(i, buffer[i]); // You could use CipStr[i] = buffer [i] or CipStr.SetAt(i, buffer[i]), but just in case... } Besides, take into account that you are changing the data in the original buffer, and maybe that's no what you want... On 2 oct, 14:23, "Eddards" <edda...(a)verizon.net> wrote: > This is what I have. > The size of the file read into buffer was 4.6mb > Why does it take so long to run through? (over a minute). > > int i; > CString CipStr; > for (i=0; i<buffer.GetSize(); i++){ > if (buffer[i] == 0x00) > buffer[i] = 0x01; > CipStr += buffer[i]; > } > > "Eddards" <edda...(a)verizon.net> wrote in message > > news:KpidnfDBIMVReljXnZ2dnUVZ_uOdnZ2d(a)giganews.com... > > > > >I tried copying the buffer with a loop like you show below. > > It took over a minute to process all 4,000,000 bytes. > > Dont know why it should take so long. > > > "Joseph M. Newcomer" <newco...(a)flounder.com> wrote in message > >news:57sac5hc63e673ijs0fdttud2annvadrno(a)4ax.com... > >> for(int i = 0; i < buffer.GetSize(); i++) > >> if(buffer[i] == 0x00) > >> buffer[i] = 0x01; > > >> What is so hard about this? This is pretty elementary C programming! > > >> If you want to do it more along the "hard way" read about the > >> MultiByteToWideChar API (and > >> see my essay on my MVP Tips site on CString techniques) > > >> joe > >> On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <edda...(a)verizon.net> > >> wrote: > > >>>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to > >>>the > >>>CString > >>>Is this possible ? > > >>>"Eddards" <edda...(a)verizon.net> wrote in message > >>>news:9fGdnWZaLPg3J1nXnZ2dnUVZ_u6dnZ2d(a)giganews.com... > >>>>I am using VC6. > >>>> Is there a way to copy a CByteArray to a CString? > > >> Joseph M. Newcomer [MVP] > >> email: newco...(a)flounder.com > >> Web:http://www.flounder.com > >> MVP Tips:http://www.flounder.com/mvp_tips.htm- Ocultar texto de la > >> cita - > > - Mostrar texto de la cita -
From: Tom Serface on 2 Oct 2009 11:08 Shoot, you're right. CString, doesn't have a SetSize() method. :o( I was sure that would work... The size for CString is determined by the null at the end. There is a GetLength() of course, but no was to set the size like other types of arrays. I should have checked the help first. Apologies. What if you tried the form of CString constructor where it is prefilled to a size using a known character. CString CipStr(_T('x'),buffer.GetSize()); I'm not sure that will make it any faster, but it may make it allocated the values for the string in one allocation call rather than resizing it for each character you add. Worth a try anyway. You could aslo try getting a pointer to the buffer, resizing it, using the pointer to put in your own characters then calling ReleaseBuffer() to put it back into the CString. Tom "Eddards" <eddards(a)verizon.net> wrote in message news:SJWdnQfW-8IbnFvXnZ2dnUVZ_sadnZ2d(a)giganews.com... > Compiler error: > error C2039: 'SetSize' : is not a member of 'CString' > > > "Mikel" <mikel.luri(a)gmail.com> wrote in message > news:f6b09929-7949-478a-a434-324702efa30c(a)j4g2000yqa.googlegroups.com... > Is it over a minute in Release mode or in Debug mode? > Anyway, for such a long buffer, I think you should set the size of the > destination string before starting to add elements. Otherwise, the > string will have to reallocate the memory as it grows, which can take > a lot of time. > > Try something like this: > > CString CipStr; > CipStr.SetSize(buffer.GetSize()); > > for (i=0; i<buffer.GetSize(); i++) > { > if (buffer[i] == 0x00) > buffer[i] = 0x01; > CipStr.SetAtGrow(i, buffer[i]); // You could use CipStr[i] = buffer > [i] or CipStr.SetAt(i, buffer[i]), but just in case... > } > > Besides, take into account that you are changing the data in the > original buffer, and maybe that's no what you want... > > On 2 oct, 14:23, "Eddards" <edda...(a)verizon.net> wrote: >> This is what I have. >> The size of the file read into buffer was 4.6mb >> Why does it take so long to run through? (over a minute). >> >> int i; >> CString CipStr; >> for (i=0; i<buffer.GetSize(); i++){ >> if (buffer[i] == 0x00) >> buffer[i] = 0x01; >> CipStr += buffer[i]; >> } >> >> "Eddards" <edda...(a)verizon.net> wrote in message >> >> news:KpidnfDBIMVReljXnZ2dnUVZ_uOdnZ2d(a)giganews.com... >> >> >> >> >I tried copying the buffer with a loop like you show below. >> > It took over a minute to process all 4,000,000 bytes. >> > Dont know why it should take so long. >> >> > "Joseph M. Newcomer" <newco...(a)flounder.com> wrote in message >> >news:57sac5hc63e673ijs0fdttud2annvadrno(a)4ax.com... >> >> for(int i = 0; i < buffer.GetSize(); i++) >> >> if(buffer[i] == 0x00) >> >> buffer[i] = 0x01; >> >> >> What is so hard about this? This is pretty elementary C programming! >> >> >> If you want to do it more along the "hard way" read about the >> >> MultiByteToWideChar API (and >> >> see my essay on my MVP Tips site on CString techniques) >> >> >> joe >> >> On Thu, 1 Oct 2009 15:09:07 -0400, "Eddards" <edda...(a)verizon.net> >> >> wrote: >> >> >>>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to >> >>>the >> >>>CString >> >>>Is this possible ? >> >> >>>"Eddards" <edda...(a)verizon.net> wrote in message >> >>>news:9fGdnWZaLPg3J1nXnZ2dnUVZ_u6dnZ2d(a)giganews.com... >> >>>>I am using VC6. >> >>>> Is there a way to copy a CByteArray to a CString? >> >> >> Joseph M. Newcomer [MVP] >> >> email: newco...(a)flounder.com >> >> Web:http://www.flounder.com >> >> MVP Tips:http://www.flounder.com/mvp_tips.htm- Ocultar texto de la >> >> cita - >> >> - Mostrar texto de la cita - > >
|
Next
|
Last
Pages: 1 2 Prev: AfxConnectionAdvise: No events fired Next: arrangement of include files |