由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - A problem about Heap and Stack.
相关主题
Char x[] = "abc"; 是在heap还是stack上? (转载)在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)
a small question about c++ object allocation问两道以前的Bloomberg题
问个C++题topercode DP问题求解
请教几个面试问题请教一道题
请教个C++编程思路明天要面 facebook 的 PhD team allocation interview, 求知情人指导
为什么C++的constructor出错可以抛出异常,而destructor出错问道G题(2)
问几道老题定义一个数组, 巨简单的一个问题
A malloc/free question using C/C++有没有人同觉得Recover Binary Search Tree的solution using O(n) space并不是那么straight forward么?
相关话题的讨论汇总
话题: stack话题: heap话题: operator话题: memory话题: object
进入JobHunting版参与讨论
1 (共1页)
c***y
发帖数: 560
1
how to enforce an object instance only be allocated on the stack rather than
the heap at compile time?
thanks a lot.
l******c
发帖数: 2555
2
override operator new?????

than

【在 c***y 的大作中提到】
: how to enforce an object instance only be allocated on the stack rather than
: the heap at compile time?
: thanks a lot.

l******c
发帖数: 2555
3
private new operator

than

【在 c***y 的大作中提到】
: how to enforce an object instance only be allocated on the stack rather than
: the heap at compile time?
: thanks a lot.

c***y
发帖数: 560
4
what does this mean? this leads to failure of calling new operator?

【在 l******c 的大作中提到】
: private new operator
:
: than

g*******y
发帖数: 1930
5
i guess you can pre-allocate some memory in compile time, and then manage
that memory yourself (memory pool alloc/free), and then redefine the new
operator (class specific operator new)

【在 c***y 的大作中提到】
: what does this mean? this leads to failure of calling new operator?
B*****t
发帖数: 335
6
There are 3 memory storage types for c++ to allocate memory for an object.
1. stack memory for object inside a function.
2. static storage for namespace-scope objects and local static objects
3. heap storage for dynamically-allocated objects.
If the stack in you problem refers to the first type of memory storage,
there is only one method that you could do this, which is defining a
function, allocating memory for an object inside a function, and using it.
You cannot use it outside of a function.

【在 c***y 的大作中提到】
: how to enforce an object instance only be allocated on the stack rather than
: the heap at compile time?
: thanks a lot.

f****4
发帖数: 1359
7
effective c++ & more effective c++上有讨论
如果禁止一个对象在stack上生成;把析构函数声明成私有函数
如果只想在heap上生成;构造函数声明成私有;同时提供虚拟构造函数(这里不是指
virtual constructor,而是指用factory patterns生成对象)
c***y
发帖数: 560
8
what's your point?
we want to get an object instance on Stack, your methods are reverse?

【在 f****4 的大作中提到】
: effective c++ & more effective c++上有讨论
: 如果禁止一个对象在stack上生成;把析构函数声明成私有函数
: 如果只想在heap上生成;构造函数声明成私有;同时提供虚拟构造函数(这里不是指
: virtual constructor,而是指用factory patterns生成对象)

a****l
发帖数: 245
9
To prohibit heap-based objects, we can declare operator new (and operator
delete) as private since it is called by the new operator.
1 (共1页)
进入JobHunting版参与讨论
相关主题
有没有人同觉得Recover Binary Search Tree的solution using O(n) space并不是那么straight forward么?请教个C++编程思路
L的team match为什么C++的constructor出错可以抛出异常,而destructor出错
发Tableau onsite面经攒人品问几道老题
我最喜欢问的问题,怎样检查out of memoryA malloc/free question using C/C++
Char x[] = "abc"; 是在heap还是stack上? (转载)在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)
a small question about c++ object allocation问两道以前的Bloomberg题
问个C++题topercode DP问题求解
请教几个面试问题请教一道题
相关话题的讨论汇总
话题: stack话题: heap话题: operator话题: memory话题: object