由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - C#中的Memory控制
相关主题
觉得C#的valuetype和boxing真的是没有必要CrystalReport 问题
.Net Formatting Objects Processor - NFOP请问:关于C#和XML的问题
SOAPHow to cancel DateTimePicker event?
请问, ASP.NET 中, 2 个web form之间如何传参数?sample code needed
.Text 简易安装A Question about Session State in ASP.NET
serialization problemc# 内存管理的一个小问题
Re: how to write an object into xml with弱问c# using, try有啥用
问题又来了.Q: c# datetime nullable objects
相关话题的讨论汇总
话题: c#话题: memory话题: list话题: element话题: getvalue
进入DotNet版参与讨论
1 (共1页)
o**f
发帖数: 76
1
我最近编了一些C#程序。有一些关于Memory的问题想请教。
The list class supports dynamic memory allocation. I
can get an element from a list with GetValue(). However,
if I modify the element I got via GetValue(), the real
element in the list is changed too. It seems that
GetValue returns the reference to that element (The C++
reference concept). Can anyone briefly describe how
memory space is managed by C#? For example, how C#
manage the memory space used by a list.
Thank you!
p*p
发帖数: 75
2
reference type, value type
box, unbox
garbage collector
this is all you need to know.
by the way, try to add "int" value to the list, get a reference, and modify
it. check the the element in the list is NOT changed. :)

【在 o**f 的大作中提到】
: 我最近编了一些C#程序。有一些关于Memory的问题想请教。
: The list class supports dynamic memory allocation. I
: can get an element from a list with GetValue(). However,
: if I modify the element I got via GetValue(), the real
: element in the list is changed too. It seems that
: GetValue returns the reference to that element (The C++
: reference concept). Can anyone briefly describe how
: memory space is managed by C#? For example, how C#
: manage the memory space used by a list.
: Thank you!

o**f
发帖数: 76
3
Thank you for your reply.
How to distinguish reference type and value type?
I know keywords like "ref" or "out" can take variables
back from a function call, but the example I mentioned
regarding List does not use these keywords.
I assume if I don't use any pointer like variable to
apply memory space, I don't need to do garbage collection.
Is this correct?
I don't know box and unbox. Can you tell me the meaning
of them or I can go to check them out online.
Thanks.

【在 p*p 的大作中提到】
: reference type, value type
: box, unbox
: garbage collector
: this is all you need to know.
: by the way, try to add "int" value to the list, get a reference, and modify
: it. check the the element in the list is NOT changed. :)

p*p
发帖数: 75
4
this is about allocation of objects. Objects can be allocated in heap, or on
stacks. if you are familar with C/C++, this concept is quite easy to know. if
you create a object by malloc() or new(),
int* p = malloc(sizeof(int))
the object is on the heap, otherwise, if you define a object in a function,
like
int n
it's on stack.
in C/C++, you have total control on where the objects are allocated. but in
C#, it depends on whether it's a reference type or value type. all primitive
types and s

【在 o**f 的大作中提到】
: Thank you for your reply.
: How to distinguish reference type and value type?
: I know keywords like "ref" or "out" can take variables
: back from a function call, but the example I mentioned
: regarding List does not use these keywords.
: I assume if I don't use any pointer like variable to
: apply memory space, I don't need to do garbage collection.
: Is this correct?
: I don't know box and unbox. Can you tell me the meaning
: of them or I can go to check them out online.

o**f
发帖数: 76
5
Hey Pip,
Really appreciate your explainations and these are very helpful for me.
Thank you!
OSPF

if
code
the
in

【在 p*p 的大作中提到】
: this is about allocation of objects. Objects can be allocated in heap, or on
: stacks. if you are familar with C/C++, this concept is quite easy to know. if
: you create a object by malloc() or new(),
: int* p = malloc(sizeof(int))
: the object is on the heap, otherwise, if you define a object in a function,
: like
: int n
: it's on stack.
: in C/C++, you have total control on where the objects are allocated. but in
: C#, it depends on whether it's a reference type or value type. all primitive

1 (共1页)
进入DotNet版参与讨论
相关主题
Q: c# datetime nullable objects .Text 简易安装
大牛指教:新手List<>问题serialization problem
C#/.Net 的垃圾回收机制 是怎么样的?Re: how to write an object into xml with
A malloc/free question using C/C++问题又来了.
觉得C#的valuetype和boxing真的是没有必要CrystalReport 问题
.Net Formatting Objects Processor - NFOP请问:关于C#和XML的问题
SOAPHow to cancel DateTimePicker event?
请问, ASP.NET 中, 2 个web form之间如何传参数?sample code needed
相关话题的讨论汇总
话题: c#话题: memory话题: list话题: element话题: getvalue