由买买提看人间百态

topics

全部话题 - 话题: deallocate
1 2 下页 末页 (共2页)
F********E
发帖数: 1025
1
Hi,
I have the following fortran90 code:
**********************************************
TYPE :: CPLK
REAL(8), DIMENSION(:), POINTER :: CP
TYPE(CPLK),POINTER :: NEXT
END TYPE CPLK
...
allocate CPLK linked list
let CPTR point to the last link
...
IF ( ASSOCIATED (CPTR) ) THEN
WRITE(OUTU,*)' deallocate this layer'
DEALLOCATE(CPTR)
ENDIF
***********************************************
Execuation o
s******g
发帖数: 755
2
【 以下文字转载自 Apple 讨论区 】
发信人: faucetQ (fq), 信区: Apple
标 题: [Mac Dev]整了个ObjectiveC的笔记,看看气氛对得上不
发信站: BBS 未名空间站 (Mon Feb 2 21:38:18 2009), 转信
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk... 阅读全帖
f*****Q
发帖数: 1912
3
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk的语法基本是相同的。
当有两个或者两个以上的参数时,通常试用以的语法
[ obj method:parameter1 WithSecondParameter:parameter2];
定义一个类的代码放在一个.h文件中,下面是一个例子。
//macdevexample1.h
... 阅读全帖
h*****g
发帖数: 944
4
来自主题: JobHunting版 - 又问几个c语言编程的题目
Q1)
what are the variable types in the statement below?
int * x, y;
a) both x and y are of type int *
b) x is of type int* and y is of type int
c) x is of type int and y is of type int*
d) both x and y are of type int
我选的是b
Q2)
which of the following is a correct declaration for a pointer to a function
that returns a double and takes no arguments?
a) double (*ptr_function)(void);
b) double (ptr_function)(void);
c) double ptr_function(void);
d) double *ptr_function(void);
Q3)
Which of the followi... 阅读全帖
g***l
发帖数: 18555
5
我找到了一个SCRIPT LOGIN的
USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
@binvalue varbinary(256),
@hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint in... 阅读全帖
h*****g
发帖数: 944
6
来自主题: Programming版 - 又问几个c语言编程的题目
Q1)
what are the variable types in the statement below?
int * x, y;
a) both x and y are of type int *
b) x is of type int* and y is of type int
c) x is of type int and y is of type int*
d) both x and y are of type int
我选的是b
Q2)
which of the following is a correct declaration for a pointer to a function
that returns a double and takes no arguments?
a) double (*ptr_function)(void);
b) double (ptr_function)(void);
c) double ptr_function(void);
d) double *ptr_function(void);
Q3)
Which of the followi... 阅读全帖
F*********k
发帖数: 42
7
各位大牛。。
我在看Andrei Alexandrescu的那本 Modern c++ design 的书,有个问题不是很明白,
不知哪位大牛看过给我解答一下。。。
书的第四章 Small-Object Allocation 里边,他设计的程序是不是存在这样一个隐患?
如果次序是这样的话:
allocate obj _aa, _bb, _cc;
deallocate _cc;
deallocate _aa;
new allocation request; // 根据他的code他会使用last deallocate的location,
// 就是 _aa
another new allocation requrest; // 根据他的code,他会使用_aa的下一个 memory
// block,那不是_bb么?我_bb没有
// deallocate啊,这不是overwrite了么?
他给出了书里边... 阅读全帖
l******e
发帖数: 94
8
来自主题: CS版 - CS 面试题求教
1. Assignment operation on classes - If I assign a class instance to another
class instance A = B What code execute ( i.e. to deal with the assignment
operator what code would the compiler have generated)?
2. Suppose there is a class dealing with memory allocations and
deallocations. It has methods to allocate/deallocate memory. Now the class
uses some memory for its implementation - for example its own metadata
maintenance. Where, in code, would I deallocate that memory?
O******e
发帖数: 734
9
Dynamic allocation in heap memory using Fortran 90/95:
integer,dimension(:),allocatable::p2i
integer::size
integer::alloc_stat
read(some_file,some_format)size
allocate(p2i(1:size),stat=alloc_stat)
if(alloc_stat.ne.0)stop"error allocating p2i"
...
deallocate(p2i,stat=alloc_stat)
if(alloc_stat.ne.0)stop"error deallocating p2i"
If you want to call a subroutine to allocate p2i, return from that
subroutine, use p2i elsewhere, then call another subroutine to deallocate
p2i, you will need to declare p2
e***t
发帖数: 78
10
来自主题: Programming版 - 问一个XCode的问题
多谢你的回复!
我改Async的那个block方式,变成了那几个 didReceiveResponse/data 函数。
现在的问题是,-(void)dealloc 它好象不是马上响应的。
我点了左上角的回到上一级页面,然后在dealloc里cancel connection,
但这个dealloc在我的connection都已经差不多完了才执行,根本没有起到cancel的作用
于是我把 [connection cancel]; 移到另外一个里:-(void)viewWillDisappera
这回到是能cancel,
我想请较的是,我在这个viewWillDisappear里面操作有没有什么潜在的问题?
d*******r
发帖数: 208
11
来自主题: JobHunting版 - 赞人品,发个L的onsite面经
名单上列了11个人。见了10个,跟名单上有临时改动,有一个的shadow没来。
1. given such a structure,
id -- list of friend ids (sorted), similar to bi-directional or
undirected graph eg.
1 -- 3 5 6
2 -- 5 8
3 -- 1 8
5 -- 1 2
6 -- 1
8 -- 2 3 9
9 -- 8
find an efficient way to decide if two ids are connected by 1 hop or 2
hop. for instance.
one hop: 1 -> 3 -> 8
two hop: 1 -> 3 -> 8 -> 9
2. design a hashtable, get, put, etc. consider thread-safety and hash
capacity resizing.
3. some introduction of th... 阅读全帖
m**q
发帖数: 189
12
来自主题: JobHunting版 - 赞人品,发个L的onsite面经
==> 谢谢分享

名单上列了11个人。见了10个,跟名单上有临时改动,有一个的shadow没来。
1. given such a structure,
id -- list of friend ids (sorted), similar to bi-directional or
undirected graph eg.
1 -- 3 5 6
2 -- 5 8
3 -- 1 8
5 -- 1 2
6 -- 1
8 -- 2 3 9
9 -- 8
find an efficient way to decide if two ids are connected by 1 hop or 2
hop. for instance.
one hop: 1 -> 3 -> 8
two hop: 1 -> 3 -> 8 -> 9
==> BFS
2. design a hashtable, get, put, etc. consider thread-safety and hash
capacity resizing.
==> has... 阅读全帖
a***f
发帖数: 45
13
来自主题: Programming版 - 关于内存泄漏
I think an pair of overloaded new and delete functions could be pretty helpful
in many cases. It records each allocated/deallocated memory block and
the statement allocating/deleting it. After the main program is ended, it could
output the memory blocks which have not been released yet and the corresponding
statements allocating them.
Besides, we could cache the memory blocks if your program allocate/deallocate
small memory blocks frequently, and the performance fo the program could be
improved
t****t
发帖数: 6806
14
来自主题: Programming版 - 几个问题

when you need to control the object instantiation, e.g. singleton.
if you don't allocate additional memory explicitly (via new), then no.
compiler will deallocate all implicitly allocated memory, e.g. subobject's
destructor will be executed. if you do allocate, then you will need to catch
whatever exception (using catch (...) ), deallocate whatever memory, then
rethrow the exception.
d****p
发帖数: 685
15
来自主题: Programming版 - Interview question: is the following code OK?
The #8 is for calling _M_put_node in rb_tree which is called by _M_destroy_
node. #7 is about dealocating the memory for current tree node. That
deallocate function has actually been called before when you erased the same
node from ~Foo(). That's why I said it is the map node (not Foo) being
deleted twice.
Set a breakpint in stl_tree.h line 273 deallocate function and you will
observe it is called twice.
The shared pointer stuff around #8 is about qualifying the map's type
l********a
发帖数: 1154
16
来自主题: Programming版 - vector的析构问题
就是个类自己包含自己的例子
例如,html的tag,


<...>


<...>
<...>
<...>


如果我用这个类A表示一个tag,每个tag下面可能有其他tag,都看做它的孩子,这样可以
对这些tag做相同的处理,如果没有孩子,它的children vector就是空的,现在需要写一
个析构函数来析构,由于vector存放的是指针形式A *,构造函数也能看出来每一个孩子
都是new出来的,调试的报错的确是在
void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
::operator delete(_Ptr);
}
往上追踪看的确是这个类的析构函数出错了,不能delete?但是现在的析构函数从流程上
好像是对的,比较郁闷
F*********k
发帖数: 42
17
好的,谢谢谢谢,我想我大概明白了,
我之前没看明白 FixedAllocator::Chunk::Deallocate 里边的
*toRelease = firstAvailableBlock_; 这句
其实这句实际上把当前和之前的连接起来了。
我把源码贴这里
void FixedAllocator::Chunk::Reset(std::size_t blockSize, unsigned char
blocks)
{
assert(blockSize > 0);
assert(blocks > 0);
// Overflow check
assert((blockSize * blocks) / blockSize == blocks);
firstAvailableBlock_ = 0;
blocksAvailable_ = blocks;
unsigned char i = 0;
unsigned char* p = pData_;
for (; i != blocks; p += blockSize)
... 阅读全帖
g********d
发帖数: 203
18
来自主题: JobHunting版 - 攒人品 报BB面经
Isn't string "Hello World" on foo's stack and it gets deallocated as soon as
foo is done?
S**I
发帖数: 15689
19
来自主题: JobHunting版 - 分享A公司面经
估计是这样:s2分配在stack上,对foo的调用结束时s2被deallocate,但是s2被分配的
那段内存还没有被覆盖,对t的赋值导致在stack上为t分配内存,于是t就指向了s2原先
指向的内存地址。
我觉得几乎不可能被利用,按标准来说这是undefined behavior,返回任何结果都是有
可能的,也包括正确的结果——但是这个不可能被事先预料到。
m****v
发帖数: 84
20
很可能会有一个在Palo Alto的实习机会,公司愿意给房子住两人间,或者给点钱自己
找。如果自己
找的话,可能会有交通不便、租金贵等问题,但是会自由很多。请问大家觉得哪个选择
比较合适呢。
谢谢。
同时在此汇报碰到过的面试题若干(来自不同公司的面试环节),抱歉之前没有整理过
,如果有时间
会把它们整理好再发一下。
算法、数据结构:
Prefix Tree
Kth element
BST serialization
quicksort
heap, heapsort
M links, find the Kth element
判断二叉树合法
按层打印二叉树
矩阵找最大和子矩阵
设计:
任务管理
交通系统
语言:
dynamic_cast, static_cast, ...
virtual function
exception in destructor
malloc, dealloc
polymorphism
regex in perl/python/etc.
数学、概率:
Monte Carlo: give an example and explain
Fibonacci series... 阅读全帖
g*********s
发帖数: 1782
21
yes, bad practice.
who allocate, who deallocate.
g*********s
发帖数: 1782
22
来自主题: JobHunting版 - 贴两道面试题

well, if the solution is like this, of course not bt. but your code still
has a mem leak.
can u call this "delete"? this node's memory is not deallocated yet. i'd
say this is a wording game.
a**U
发帖数: 115
23
来自主题: JobHunting版 - 一个C++面试题
delete p; 问题在那里?
是不是array中某个char是'\0', 比如说p[3]='\0',后面的就没有删掉?
还是说delete p就只是删了第一个char?
char* p = (char*)malloc(10);
如果用delete(p)是不是只是deallocate第一个char?
g********E
发帖数: 178
24
来自主题: JobHunting版 - 问个C++的基础问题
查了下原来析构是destruct,明白了,如果我就用默认的,
This destroys all container elements, and deallocates all the storage
capacity allocated by the vector using its allocator.
这样是不是析构就不如clear/resize快?
resize不错,非常符合我的需要:)

call
p********g
发帖数: 61
25
来自主题: JobHunting版 - 请教一个入门级的C的指针问题
each function has its own stack.
When you call copy(), it creates a new frame and initializes s to &a, t to &
b. So s and &a points to the same memory location, but they are different.
After you assign s to t, both of them hold the memory location of a. When
you return, you are just returning the memory address of a, and both s and t
are deallocated.
c gets this pointer, and that's why it prints out 1.
s********r
发帖数: 403
26
来自主题: JobHunting版 - 怎么看process 用多少内存? (转载)
Red Hat 5 Enterprise? 这种企业级 commercial 的产品有这种问题未免太搞笑。
不过有可能有修改过的内存管理模块, lazy deallocation?
建议你这样试试,
char *mem = (char*) malloc(sizeof(char)*(1<<30));
getchar();
free(mem);
getchar();
起同样的进程,第一个进程在 free() 后的getchar()停住,
然后起足够多个同样的进程,在 malloc() 后的getchar() 停住,看会不会把第一个的
进程free() 掉的空间给拿回来。
b***e
发帖数: 1419
27
来自主题: JobHunting版 - 与 Java 相比,Ruby 有啥优势?
Google V8 uses full fledged incremental mark & copy technology for
garbage collection, which is, if not more, the same strong as
most JVM garbage collection.
The only language that I know who's stilling doing reference
counting is PHP . Objective C (IOS) sort of does reference
counting, but it's soft garbage collection as you can always use
explicit language primitives to deallocate memory.
I think you just lack basic experience in JS, in which case, I
really suggest you STFU.
a****Q
发帖数: 83
28
来自主题: JobHunting版 - 电面两题
please not bother lock/synchronized any more...
always try lockfree version if by any means possible.
easier using Java as memeory alloc/dealloc is taken care of by gc.
much more difficult using C++.
s********u
发帖数: 1109
29
来自主题: JobHunting版 - 这道设计题怎么做?
对的,好多题目都是producer-consumer这样,blockingqueue就是最典型的。
不过memAlloc应该是take吧,就是consumer,memDealloc是释放空间的,是producer
请教下,比如要alloc的时候,怎么找空闲的位置,就linear的去找么?然后dealloc的
时候,标记一下这段空间表示清空?

了。
f******p
发帖数: 173
30
来自主题: JobHunting版 - Thread safe strcpy ??
搜了一下,https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/
yBrUjgvGwf8 里面有一个回复我觉得挺不错,大家来说说怎样
Much better to allocate a block of storage (either a general "new" or
your own sub-allocator), copy the string into it, pass it to the recipient,
and let the
recipient release it (either delete or your own deallocation back to your
pool of
buffers). This means that there is never more than one thread, ever, using
the storage.
You do not protect the function; you protect the area it is copying ... 阅读全帖
x*******9
发帖数: 138
31
来自主题: JobHunting版 - 问一个关于c++的很傻的问题,多谢
allocate on stack is faster than on heap, and it will take the advantage on
cache optimization
however, instance on stack is only available in current code block.
instance on heap is available everywhere if you get the pointer, but it's
slower and you have to deallocate it when you don't need them
r***s
发帖数: 737
32
来自主题: JobHunting版 - 面试不问算法,才能体现水平
我来试试

从你的描述来看系统是用 c++写的。要找出问题在哪里得看你在什么系统上有什么
profiling
的工具了。profiling的目的是找出 allocation site (src file/line number)of
the memory objects that take most memory. 然后我就没招了,只能读code看那个
allocated objects啥时候就不用了,再决定哪里做deallocate。
再有,啥叫大规模修改?如果不让改的话这种恶心问题我只能做reducency backup and
rolling restart.
首先得判定是否真的是网络造成的,就算是网络问题,哪些机器之间的网络问题? 这
个得先大概了解high level component dependency relationship,看看是不是cpu
memory disk都没有问题。 可以profile几个机器看看是不是 a lot of time spent
waiting for network calls.
判定是网络问题之后看是哪些components之间,或是某... 阅读全帖
t********p
发帖数: 33
33
there exists the situation that u allocate a special space in
ur heart for some special one, he/she is not anymore in ur real
life... maybe later u'll deallocate this space back, but please
don't deny that at this very moment, he/she occupies the spot,
and is like the candle to light your heart to go through lonely
dark night. :)
c********g
发帖数: 1173
34
来自主题: Apple版 - 有懂obj-c 的吗? (转载)
你这样会有memory leak。
应该把currentPath 定义成property,然后赋值时用
self.currentPath = indexPath;
最后在dealloc里:
[currentPath release];
a****a
发帖数: 5763
35
2011年12月3日,LLVM 3.0正式版发布,完整支持所有ISO C++标准和大部分C++ 0x的新
特性, 这对于一个短短几年的全新项目来说非常不易。
开发者的惊愕
在2011年WWDC(苹果全球开发者大会)的一场与Objective-C相关的讲座上,开发者的
人生观被颠覆了。
作为一个开发者,管理好自己程序所使用的内存是天经地义的事,好比人们在溜狗时必
须清理狗的排泄物一样(美国随处可见“Clean up after your dogs”的标志)。在本
科阶段上C语言的课程时,教授们会向学生反复强调:如果使用malloc函数申请了一块
内存,使用完后必须再使用free函数把申请的内存还给系统——如果不还,会造成“内
存泄漏”的结果。这对于Hello World可能还不算严重,但对于庞大的程序或是长时间
运行的服务器程序,泄内存是致命的。如果没记住,自己还清理了两次,造成的结果则
严重得多——直接导致程序崩溃。
Objective-C有类似malloc/free的对子,叫alloc/dealloc,这种原始的方式如同管理C
内存一样困难。所以Objective-C中的内存管理又增... 阅读全帖
o*****1
发帖数: 4
36
来自主题: CS版 - Two interview questions? (转载)

1. I don't know, memcpy should be the faster way, right? Or probablly you want
to use assembly string copy instruction? (Only exist for Intel platform, as
far as I know) I really can't find a way to make it faster.
2. Normally when you have tons of malloc and free and the data could be reused
, or when the memory is very small and you have to be very careful when
allocating/deallocating the memory. For example, in the STL you could provide
an allocator by yourself and some implementation did us
S*******s
发帖数: 13043
37
来自主题: Database版 - can I create a recordset with cursor?
what I want to is like this:
declare @acc int,@id int,@count int
decalre my_cursor cursor for
select id, count from sometable
set @acc=0
open my_cursor
fetch next from my_cursor
into @id,@count
while @@fetch_status=0
begin
@acc=@acc+@count
-- i want to insert a new raw to the recordest returned, but how?
insert_to_recorset @id,@acc
fetch next from my_cursor
into @id,@count
end
close my_cursor
deallocate my_cursor
p*****s
发帖数: 1780
38
我想把一些变量追加到文本文件,但不知道怎么写,特来请教。
DECLARE @name VARCHAR(50)
DECLARE db_cursor CURSOR FOR
SELECT name
FROM [master].[sys].[databases]
WHERE name NOT IN ('tempdb')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
-- 这里就想把变量@name的值输出到 c:\1.txt
-- 类似于dos命令 echo @name >> c:\1.txt
-- 请问sql命令该怎么写?
-- 谢谢
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
z***y
发帖数: 7151
39
这个不奇怪啊。
你可以看一看那个procedure, 你看里面有几个对temp table 的改变, 这些数据的改
变都会触发
recompilation。
我这个版本是2008 SP2的。
create procedure sys.sp_replmonitorrefreshagentdata
as
begin
set nocount on
declare @retcode int
,@agent_id int
,@agent_id2 int
,@publisher_id int
,@xact_seqno varbinary(16)
,@logreader_latency int
,@publisher_db sysname
,@publication sysname

-- security check
-- Has to b... 阅读全帖
H******6
发帖数: 51
40
MS SQL, use cursor to do this. It works.
Use Test2
go
Declare WebAd_cursor cursor
STATic
For
Select Website,StartDate,EndDate,totalAmount,DaylyAmount
from WebAds1
declare @Website varchar(50),
@StartDate date,
@EndDate date,
@totalAmount float,
@DailyAmount float

Open WebAd_cursor
IF @@CURSOR_ROWS>0
Begin
Fetch next from WebAd_cursor into
@Website ,
@StartDate ,
@EndDate ,
@totalAmount ,
@DailyAmount
while @@FETC... 阅读全帖
y********o
发帖数: 61
41
来自主题: Database版 - 请帮忙读懂这个sql script
请问这个procedure干什么用的?sql 蝌蚪,读不懂啊~~求高人指点
USE [CFH_ODS]
GO
/****** Object: StoredProcedure [dbo].[DQ_VALIDATE] Script Date: 07/13/
2015 15:08:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DQ_VALIDATE](@tableID bigint = null, @fldID bigint =
null)
AS
BEGIN
SET NOCOUNT ON
declare @VAL_ID bigint;
--
INSERT INTO DQ_VAL(VAL_START_DT) values(GETDATE());
SELECT @VAL_ID = @@IDENTITY;
DECLARE c CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY
... 阅读全帖
x****e
发帖数: 1773
42
来自主题: Database版 - 请帮忙读懂这个sql script
USE [CFH_ODS]
GO
/****** Object: StoredProcedure [dbo].[DQ_VALIDATE] Script Date: 07/13/
2015 15:08:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DQ_VALIDATE](@tableID bigint = null, @fldID bigint =
null) -- This proc takes @tablID and @fldID arguments.
-- No idea what this proc does without knowing about the procs it calls, and
all the tables that are involved in the whole process.
AS
BEGIN
SET NOCOUNT ON
declare @VAL_ID bigint; -- Declare an ... 阅读全帖
r**a
发帖数: 630
43

it is a trick, but it is pretty annoying, hoho, not much different from the
deallocation of pointers
b******y
发帖数: 9224
44
来自主题: Java版 - garbage collection issue
No idea yet. What kind of tool you used for profiling the java GC process?
It might be your application has frequent memory allocation and deallocation
going on?
z**********r
发帖数: 86
45
来自主题: Programming版 - size不固定的struct怎么定义呀?
我是这么用的(verified on Ubuntu):
typedef struct
{
// fixed length data
int len;
// any varying length data should be put below
// note, you must be used data[] instead of *data
// because data[] does't take extra space; *data takes four bytes for the
pointer
char data[];
}Array;
// for allocate
int len=10;
Array *x=(Array *)malloc(len*sizeof(char)+sizeof(Array));
x->len=10;
// access the varying length part
x->data[0]='c';
// for deallocate
free(x);
h******t
发帖数: 4
46
来自主题: Programming版 - C++ class cross reference problem
Thanks a lot. It certainly works. I would like to learn more from you. Why can
I not use reference? By using pointers, I have to maintain memory allocation
on my own. For example, if I have a set like
std::set s1;
Whenever I insert a pointer to an object of index_object_1 to the set, I have
to deallocate it when I finish with the object. Sometimes, it is hard to track
if I release all the memory allocated. Is the way you suggested the only way
to make
c*r
发帖数: 278
47
来自主题: Programming版 - 关于内存泄漏
This is way to detect/debug memory leakage, not a way to avoid it.

helpful
could
corresponding
deallocate
code.
of
p***o
发帖数: 1252
48
来自主题: Programming版 - 几个问题

catch
compiler will deallocate the obejct for you if you are using new and
the constructor throw an exception, say
T *t = new T(p);
Compiler will first call (equivalently) operator new() then new (t) T(p).
If T(p) throws then compiler will call operator delete. You don't need to
do it explicitly. I remember Sutter once talked about this when suggesting
to write operator delete, see
http://www.gotw.ca/gotw/010.htm
c*****g
发帖数: 119
49
来自主题: Programming版 - 一个interview问题,关于内存泄漏
sgi definition:
memory leak
Making malloc calls without the corresponding calls to free. The result
is that the amount of heap memory used continues to increase as the process
runs.
pcmag defintition:
When memory is allocated, but not deallocated, a memory leak occurs (the
memory has leaked out of the computer).
这些是通常的定义,当然本来就没啥标准定义。
O******e
发帖数: 734
50
来自主题: Programming版 - 问个fortran的问题
It declares a one-dimensional integer array that is allocatable (you can
allocated whatever number of elements or amount of memory is needed) and
is also saved between allocations of the function or subroutine (the
array will not be deallocated when the subroutine or function returns).
1 2 下页 末页 (共2页)