由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - A malloc/free question using C/C++
相关主题
Windows下多个DLL之间memory allocation问题 (转载)Char x[] = "abc"; 是在heap还是stack上? (转载)
我最喜欢问的问题,怎样检查out of memory为什么C++的constructor出错可以抛出异常,而destructor出错
请教个C++编程思路A problem about Heap and Stack.
求助:面试题bloomberg onsite
问一个C的简单问题问个malloc问题
在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)QUALCOMM一题
Googlec interview question
C++ Q78: about sizeof新手,一个C 库的问题
相关话题的讨论汇总
话题: pstr话题: free话题: memory话题: function话题: fun
进入JobHunting版参与讨论
1 (共1页)
G***n
发帖数: 877
1
Hi,
I have a question using C. I want to
allocate the memory using realloc() or
malloc() inside a function fun(), the
return of this function is the pointer
pointing to the allocated memory. There
is no free() inside fun(), because I
need to grasp the allocated memory in
fun() by its return.
In the main function, I define char
*pStr= fun() to call this function and
then try to free pStr later using
free(pStr). The program runs forever at
free(pStr) there. However, if I do not
use free() function to release the
memory, the code can pass the test.
That mean I cannot use free() to free
pStr returned by a function. Then my
question is how to release the memory
space allocated inside fun()? If I
don't use free(), the code pass the
test, however, I think the memory
without release would be wrong once the
memory is full.
Does anyone have any idea of what I am
wrong here?
1 (共1页)
进入JobHunting版参与讨论
相关主题
新手,一个C 库的问题问一个C的简单问题
报个电面的面经和据信吧, 求安慰在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)
求问CC150书上16.9的“multiple of alignment”是什么意思??Google
感觉G家面试还是和面的组工作内容略微相关的C++ Q78: about sizeof
Windows下多个DLL之间memory allocation问题 (转载)Char x[] = "abc"; 是在heap还是stack上? (转载)
我最喜欢问的问题,怎样检查out of memory为什么C++的constructor出错可以抛出异常,而destructor出错
请教个C++编程思路A problem about Heap and Stack.
求助:面试题bloomberg onsite
相关话题的讨论汇总
话题: pstr话题: free话题: memory话题: function话题: fun