这是ATL COM实现里的一个成员函数中的一个操作,简单实现在字符串中的每个'后再加个',但字符串大于2,3百K时会造成"OUT of stack space",谁能分析一下原因?
char *s=new char[1024*1024],*s3=s;
strcpy(s,W2A(m_OriginalText.m_str));
char *s1=new char[1024*1024],*s2=s1;
while(*s)
{
*s1++=*s;
if(*s++=='\'')
{
*s1++='\'';
}
}
*s1='\0';
wcscpy(m_OriginalText,A2W(s2));
delete[] s3,s2;
char *s=new char[1024*1024],*s3=s;
strcpy(s,W2A(m_OriginalText.m_str));
char *s1=new char[1024*1024],*s2=s1;
while(*s)
{
*s1++=*s;
if(*s++=='\'')
{
*s1++='\'';
}
}
*s1='\0';
wcscpy(m_OriginalText,A2W(s2));
delete[] s3,s2;
解决方案 »
- 怎样绘制直线?
- 关于数据结构的问题
- 关于缺少';'的一个错误
- 请问哪里有Inside Microsoft Windows 2000中文版下载啊,急用啊!!共享一下吧
- 请问我要保存文件路径不写配置文件,也不写在注册表中怎么办?谢谢!
- 如何得到CEdit當前的光標位置
- 两个模态对话框互相切换几次后应用程序错误
- 如何制作文件保险箱
- 有关winsock发送数据的问题,up也有分啊!
- 我下载了一些加密算法为何在VC编译过程中总是出现C1010错误呢?Keywords:encrypt
- 求教:关于命名空间(namespace)的问题?!!!!!!!!!!
- 请问谁有GSM3.40(中文版) 、SMPP3.3 (中文版) cmpp1.2 (梦网上的有错误)?
{
*s1++=*s;
if(*s++=='\'') ///at this moment, *s++ means *s,not *(s+1),so you probably have double size of results,since sizeof(s)=sizeof(s1) and include sizeof('),the occured error is common,i think.
{
*s1++='\'';
}
}
TO-> quengzi(code) :MoveMemory()是什么?
TO->CMemFile:CMemFile知到没用过,你用CMemFile帮我写一下好么?
TO->所有人:ATL里有这方面的限制么?
strcpy(s,W2A(m_OriginalText.m_str));
这一句可能会造成越界,
如果你不能确保W2A(...)的结果一定小于sizeof(s),
或者不确保W2A(...)的结果有结束符。
str.replace("'","''");
wcscpy(m_OriginalText,A2W(str));
可能over flow
那么就先把他分割成大小100K的
然后在分别进行你的这个操作
操作完成后char laststr[1024*1024];
ZeroMemory(laststr,1024*1024);
strcat(laststr,strpart1);
strcat(laststr,strpart2);
.................还有一点,你要确保laststr足够大
TO->zheng_rui(第二刀) :我是ATL里
TO->ZHENG017(风中王子):谢了,老朋友,但这是个需要解决的问题,实在不行我在用LIST
TO-> snsins(不再信仰,不再坚持):看似笨办法,但值得一试,谢谢.
TO->所有人:谁有在ATL里处理大字符串的经验,欢迎指教,谢谢.
((_lpa = lpa) == NULL) ? NULL : (\
_convert = (lstrlenA(_lpa)+1),\
ATLA2WHELPER((LPWSTR) alloca(_convert*2), _lpa, _convert)))#define W2A(lpw) (\
((_lpw = lpw) == NULL) ? NULL : (\
_convert = (lstrlenW(_lpw)+1)*2,\
ATLW2AHELPER((LPSTR) alloca(_convert), _lpw, _convert)))问题在于他们是通过调用 alloca 分配转换需要的临时内存块的!
以下是MSDN中关于 alloca 的解释:Allocates memory on the stack.这样就能解释为何字符串达2~300k就会出现"OUT of stack space"了。
WideCharToMultiBytes 或 MultiBytesToWideChar,以下是 W2A, A2W 两个红调用的 Helper 函数在MFC中的实现:LPWSTR AFXAPI AfxA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars)
{
if (lpa == NULL)
return NULL;
ASSERT(lpw != NULL);
// verify that no illegal character present
// since lpw was allocated based on the size of lpa
// don't worry about the number of chars
lpw[0] = '\0';
VERIFY(MultiByteToWideChar(CP_ACP, 0, lpa, -1, lpw, nChars));
return lpw;
}LPSTR AFXAPI AfxW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars)
{
if (lpw == NULL)
return NULL;
ASSERT(lpa != NULL);
// verify that no illegal character present
// since lpa was allocated based on the size of lpw
// don't worry about the number of chars
lpa[0] = '\0';
VERIFY(WideCharToMultiByte(CP_ACP, 0, lpw, -1, lpa, nChars, NULL, NULL));
return lpa;
}