使用 C_CG::Configuration::EnableSegmentedMemory 內容可以啟用或停用您的應用程式的記憶體分段程式碼產生。
可以使用下列內容將屬性指派給特定的記憶體區段:
雖然它們是屬性層次內容,但是使用這些內容的最有效方式如下所示:
使用如下所示的記憶體區段內容:
struct myClass {
uint8 attr1;
...
struct myClass_Seg1 <far> * itsSeg1;
struct myClass_Seg2 <far> * itsSeg2;
...
}
在此程式碼範例中,<far> 將會由您使用 FarPointerQualifier 內容指定的 whatever 程式碼所取代。當您為 MemorySegmentName 內容提供區段名稱時,產生的程式碼包括其名稱連結類別名稱與記憶體區段名稱的新結構。此結構包含已指派給此記憶體區段的所有屬性。
由於將在相關記憶體區段結構中宣告屬性,因此您可能遇到以下狀況:您在模型的給定類別中定義的屬性會結束在其中多個記憶體區段結構之間進行散布。為代表模型中的類別類型而產生的結構將包括指向這些屬性的指標。
#pragma data_seg("ROM")
#pragma data_seg(DEFAULT)
因為針對模型中的類別定義的屬性可能結束在所產生程式碼中的不同記憶體區段結構之間進行散布,所以 Rational Rhapsody 會提供用於存取此資料的巨集,而無需指定所指派至的記憶體區段。用於巨集的格式取決於 C_CG::Attribute::SegmentedAttributeMacroName 內容的值。
比方說,如果您保留該內容的預設值(即 $class_$attribute),則產生的程式碼將類似於:#define file_0_variable_0 file_0_Seg1.variable_0
此外,透過 MicroC 設定檔,您可以將所有關係及流程埠指派給特定的記憶體區段。
若要將關係及流程埠指派給特定的記憶體區段:
此範例顯示如何將針對記憶體分段內容指定的值反映在 Rational Rhapsody 所產生的程式碼中。
| 內容名稱 | 內容值 |
|---|---|
| C_CG::Configuration::DefaultROMSegmentName | ROM |
| C_CG::Configuration::FarPointerQualifier | 遠 |
| for first segment (stereotype applied to variable_0 in file_0 model): | |
| C_CG::Attribute::MemorySegmentName | Seg1 |
| C_CG::Attribute::MemorySegmentSpecificationProlog | #pragma DATA_SEG $seg |
| C_CG::Attribute::MemorySegmentSpecificationEpilog | #pragma DATA_SEG DEFAULT |
| C_CG::Attribute::MemorySegmentImplementationProlog | #pragma DATA_SEG $seg |
| C_CG:Attribute:MemorySegmentImplementationEpilog | #pragma DATA_SEG DEFAULT |
| C_CG::Attribute::SegmentedAttributeMacroName | $class_$attribute |
| for second segment (stereotype applied to variable_1 in file_0 in model): | |
| C_CG::Attribute::MemorySegmentName | Seg2 |
| C_CG::Attribute::MemorySegmentSpecificationProlog | #pragma DATA_SEG "$seg" |
| C_CG::Attribute::MemorySegmentSpecificationEpilog | #pragma DATA_SEG DEFAULT |
| C_CG::Attribute::MemorySegmentImplementationProlog | #pragma DATA_SEG "$seg" |
| C_CG:Attribute:MemorySegmentImplementationEpilog | #pragma DATA_SEG DEFAULT |
| C_CG::Attribute::SegmentedAttributeMacroName | $class_$attribute |
#ifndef file_0_H
#define file_0_H
/*## auto_generated */
#include "mxf\Ric.h"
/*## auto_generated */
#include "Default.h"
/*## package Default */
/*## class TopLevel::file_0 */
/*#[ ignore */
typedef struct file_0_Seg1_t {
int variable_0; /*## attribute variable_0 */
} file_0_Seg1_t;
#define file_0_variable_0 file_0_Seg1.variable_0
typedef struct file_0_Seg2_t {
int variable_1; /*## attribute variable_1 */
} file_0_Seg2_t;
#define file_0_variable_1 file_0_Seg2.variable_1
/*#[ ignore */
#pragma DATA_SEG Seg1
/*#]*/
extern struct file_0_Seg1_t file_0_Seg1;
/*#[ ignore */
#pragma DATA_SEG DEFAULT
/*#]*/
/*#[ ignore */
#pragma DATA_SEG "Seg2"
/*#]*/
extern struct file_0_Seg2_t file_0_Seg2;
/*#[ ignore */
#pragma DATA_SEG DEFAULT
/*#]*/
/*#]*/
/*** User explicit entries ***/
#endif
/******************************************************************
檔案路徑:DefaultComponent\DefaultConfig\file_0.h
*****************************************************************/
/*## auto_generated */ #include "file_0.h" /*## package Default */ /*## class TopLevel::file_0 */ /*#[ ignore */ /*#[ ignore */ #pragma DATA_SEG Seg1 /*#]*/ struct file_0_Seg1_t file_0_Seg1; /*#[ ignore */ #pragma DATA_SEG DEFAULT /*#]*/ #pragma DATA_SEG "Seg2"struct file_0_Seg2_t file_0_Seg2; /*#[ ignore */ #pragma DATA_SEG DEFAULT /*#]*/ /*#]*/ /********************************************************************* 檔案路徑:DefaultComponent\DefaultConfig\file_0.c *********************************************************************/