简体   繁体   English

Oracle内部 - varchar和垃圾回收

[英]Oracle Internals - varchar and garbage collection

My question is based on the following: I have a code block in which I have defined a varchar string, like this: 我的问题基于以下内容:我有一个代码块,我在其中定义了一个varchar字符串,如下所示:

v_string varchar(100);

My code block is something like this: 我的代码块是这样的:

...   
v_string := 'x = ' || x || ', y = ' || y;
...

That is, v_string is a text that I'm using to log x and y values. 也就是说, v_string是我用来记录xy值的文本。

Can anyone explain how Oracle stores such concatenated strings? 任何人都可以解释Oracle如何存储这样的连接字符串? I mean, does it put these in a heap? 我的意思是,它是否将这些放在一堆? If so, will (can) these be garbage collected? 如果是这样,将(可以)这些垃圾收集? Does that affect performance too much? 这会影响性能吗?

Thanks! 谢谢!

There will be no interim objects created so there will be nothing to garbage collect. 将不会创建临时对象,因此将无法进行垃圾回收。

When you declare v_string , Oracle allocates 100 bytes of storage (assuming your NLS_LENGTH_SEMANTICS is the default of BYTE ) for the string (larger strings will not be pre-allocated like this and what constitutes a "larger string" is version dependent. In 11.2, the limit appears to be 4000 bytes though it used to be 2000 bytes and I'm not sure when it changed). 当您声明v_string ,Oracle会为字符串分配100个字节的存储空间(假设您的NLS_LENGTH_SEMANTICSBYTE的默认值)(较大的字符串不会像这样预先分配,构成“较大字符串”的内容依赖于版本。在11.2中,限制似乎是4000字节,虽然它曾经是2000字节,我不知道它什么时候改变了)。 Since the 100 byte buffer has been pre-allocated, it's easy enough to concatenate various other strings together in that pre-allocated buffer. 由于100字节缓冲区已经预先分配,因此很容易在预分配的缓冲区中将各种其他字符串连接在一起。 There is no need to allocate any additional space to store interim results so there are no resources to free up. 没有必要分配任何额外的空间来存储临时结果,因此没有资源可以释放。

At some point, v_string will go out of scope and the buffer that was allocated for it will be freed, of course. 在某些时候, v_string将超出范围,当然将释放为其分配的缓冲区。 But that will be at the end of the block where v_string is declared. 但是这将在声明v_string的块的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM