How to use the non-modifiable pointer descriptor — TPtrC

原创 2007年10月09日 11:22:00

下面的内容摘自Symbian S60 3rd Edition SDK,先把英文原版贴在这里,等时间充足的时候我再把它翻译出来。How to use the non-modifiable pointer descriptor — TPtrC《如何使用不可修改的指针描述符TPtrC》

How to use the non-modifiable pointer descriptor — TPtrC

Non-modifiable pointer descriptors are useful for referencing constant strings or data; for example, accessing strings built into ROM resident code, or passing a reference to data in RAM which must not be modified through that reference.

  • For text data, it is usual to construct a TPtrC type and allow the appropriate variant, either a TPtrC8 or a TPtrC16 to be selected at build time.

  • For binary data, an explicit TPtrC8 is used.

  • It is rare to use an explicit TPtrC16.


Constructing a TPtrC

A non-modifiable pointer descriptor can be constructed in a number of ways:

  • any other descriptor.

  • another non-modifiable pointer descriptor.

  • a pointer into memory and specifying the length of the data.

  • a zero terminated string.

The following code fragment constructs a TPtrC to represent the data already represented by any other type of descriptor.

The source descriptor is a literal which is converted to descriptor type.

_LIT(KText,"Hello World!");
...
TBufC<16> buf1(KText); // buf1 is the existing descriptor
...
TPtrC ptr(buf1); // data in buf1 now accessible through ptr

The following code fragment constructs a TPtrC to represent the data already represented by another TPtrC.

_LIT(KText,"Hello World!");
...
TBufC<16> buf1(KText); // buf1 is the existing descriptor
...
TPtrC ptr1(buf1); // data in buf1 now accessible through ptr1
TPtrC ptr2(ptr1); // data also accessible through ptr2

Although rarely used (possibly in porting legacy 'C' code), the following code fragment defines a constant ‘C’ style non-Unicode string and then constructs the non-modifiable pointer descriptor for that string. The explicit 8 bit variant is used here. The descriptor is separate from the data it represents.

const TText8* cstr = (TText8*)"Hello World!";
...
TPtrC8 ptr(cstr);
...
ptr.Length(); // The length is 12.
ptr.Ptr(); // The address of the descriptor's data,
                    // i.e. 'C' string.

The following code fragment shows construction from a pointer into memory and a length. The example assumes that both the pointer and the length have valid values:

TUint8* memptr;
TInt length;
...
TPtrC8 ptr(memptr,length);


Accessing data

Once a non-modifiable pointer descriptor has been constructed, the functions in the base class, TDesC, are available to access the data.

For example, given a pointer descriptor labelled ptr:#

_LIT(KText,"Hello World!");
...
TBufC<16> buf1(KText); // buf1 is the existing descriptor
...
TPtrC ptr(buf1); // data in buf1 now accessible through ptr
...
ptr.Length(); // returns the length of the data (i.e. 12)


 

Objective-C 警告相关说明

原文地址:http://nshipster.com/clang-diagnostics/
  • icmmed
  • icmmed
  • 2014年09月03日 16:36
  • 9917

scikit-learn:class and function reference(看看你到底掌握了多少。。)

http://scikit-learn.org/stable/modules/classes.html#module-sklearn.decomposition Referenc...
  • mmc2015
  • mmc2015
  • 2015年08月20日 08:11
  • 3278

gcc较高版本的一些编译警告收集

最近整理了下代码警告问题。这里记录一下。
  • subfate
  • subfate
  • 2015年05月06日 13:00
  • 2633

An Appwizard to Generate Non-COM Projects that can use ATL O

  • 2006年02月23日 09:05
  • 11KB
  • 下载

This application shows how to create non rectangular buttons

  • 2006年02月23日 09:05
  • 10KB
  • 下载

How to read and understand a scientific paper: a guide for non-scientists

How to read and understand a scientific paper: a guide for non-scientists        网站链接:http://viole...
  • liyuanhao1114
  • liyuanhao1114
  • 2013年12月17日 10:11
  • 1045

How to Partition a Non-partitioned Table [ID 1070693.6]

How to Partition a Non-partitioned Table [ID 1070693.6] Modified 03-MAR-2010     Type BULLETIN     S...
  • tianlesoftware
  • tianlesoftware
  • 2011年03月02日 17:13
  • 12981

how to use htmleditor

  • 2015年07月19日 18:17
  • 4.43MB
  • 下载

Leadership How to Get IT Research You Can Use

  • 2012年12月29日 18:47
  • 28KB
  • 下载

How to use microsoft access

  • 2014年05月23日 08:38
  • 896KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to use the non-modifiable pointer descriptor — TPtrC
举报原因:
原因补充:

(最多只允许输入30个字)