Using Automatic Shared Memory Management (97)

本文介绍如何通过设置SGA_TARGET参数启用自动共享内存管理功能,并详细解释了如何使用Oracle Enterprise Manager或SQL*Plus进行配置。此外还提供了V$SGA_TARGET_ADVICE视图的使用建议,帮助确定合适的SGA_TARGET值。

You enable the automatic shared memory management feature by setting the
SGA_TARGET parameter to a non-zero value. This parameter in effect replaces the
parameters that control the memory allocated for a specific set of individual
components, which are now automatically and dynamically resized (tuned) as needed.

Note: The STATISTICS_LEVEL initialization parameter must be set
to TYPICAL (the default) or ALL for automatic shared memory
management to function.

The SGA_TARGET initialization parameter reflects the total size of the SGA. Table2–3
lists the SGA components for which SGA_TARGET includes memory—the
automatically sized SGA components—and the initialization parameters
corresponding to those components.

In addition to setting SGA_TARGET to a non-zero value, you must set the value of all
automatically sized SGA components to zero to enable full automatic tuning of these
components.

Alternatively, you can set one or more of the automatically sized SGA components to a
non-zero value, which is then used as the minimum setting for that component during
SGA tuning. This is discussed in detail later in this section.

Note: An easier way to enable automatic shared memory
management is to use Oracle Enterprise Manager (EM). When you
enable automatic shared memory management and set the Total SGA
Size, EM automatically generates the ALTER SYSTEM statements to
set SGA_TARGET to the specified size and to set all automatically sized
SGA components to zero.
If you use SQL*Plus to set SGA_TARGET, you must then set the
automatically sized SGA components to zero or to a minimum value.

The V$SGA_TARGET_ADVICE view provides information that helps you decide on a
value for SGA_TARGET.

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10599713/viewspace-996175/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10599713/viewspace-996175/

### C++ 内存泄露相关面试题及解答 #### 1. What is a memory leak in C++? A memory leak in C++ occurs when a program allocates memory dynamically using `new` or `new[]` but fails to release it using `delete` or `delete[]`. This results in the allocated memory not being freed, leading to inefficient memory usage and potential system instability over time[^1]. #### 2. How can you detect memory leaks in C++? Memory leaks can be detected using several methods: - **Manual code review**: Checking for every allocation with `new` and ensuring there's a corresponding `delete`. - **Static analysis tools**: Tools like Valgrind (for Linux) or Visual Studio's built-in diagnostics can help identify memory leaks. - **Smart pointers**: Using smart pointers such as `std::unique_ptr` and `std::shared_ptr` helps manage memory automatically and reduce the risk of leaks. #### 3. What are common causes of memory leaks in C++? Common causes include: - Forgetting to delete dynamically allocated memory. - Losing all references to dynamically allocated memory before deleting it. - Improper use of raw pointers without proper ownership semantics. For example, the following code may result in a memory leak if not handled correctly: ```cpp void exampleFunction() { int* ptr = new int(10); // Forgot to delete ptr } ``` This code allocates memory but does not free it, resulting in a memory leak[^2]. #### 4. How can you prevent memory leaks in C++? Preventive measures include: - **Using smart pointers**: Prefer `std::unique_ptr` for single ownership and `std::shared_ptr` for shared ownership. - **RAII (Resource Acquisition Is Initialization)**: Acquire resources in object constructors and release them in destructors to ensure automatic cleanup. - **Proper exception handling**: Ensure that exceptions do not bypass cleanup code by using RAII or try-catch blocks appropriately. #### 5. Can you explain how to use Valgrind to detect memory leaks? Valgrind is a powerful tool for detecting memory leaks in C++. To use Valgrind: - Compile your program with debugging information (`-g` flag). - Run the program using Valgrind with the `--leak-check=full` option. - Review the output to identify any unfreed memory blocks and their allocation sites. Example command: ```bash valgrind --leak-check=full ./your_program ``` #### 6. What is the difference between `std::unique_ptr` and `std::shared_ptr` in terms of memory management? - **`std::unique_ptr`**: Ensures exclusive ownership of the managed object. It cannot be copied, only moved, which makes it suitable for scenarios where only one owner is needed. - **`std::shared_ptr`**: Allows multiple pointers to share ownership of the same object. The object is destroyed when the last `shared_ptr` pointing to it is destroyed. Both types help prevent memory leaks by automatically managing the lifecycle of dynamically allocated objects. #### 7. How does improper use of raw pointers contribute to memory leaks? Raw pointers (`T*`) do not have automatic memory management. If a function or method allocates memory with `new` and assigns it to a raw pointer without ensuring that `delete` is called, the memory will not be freed, leading to a leak. Additionally, if an exception is thrown before `delete` is called, the cleanup might be bypassed entirely.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值