动态创建的结构??? [英] Dynamically created structures ???

查看:48
本文介绍了动态创建的结构???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在运行时有效地构建数据结构。

这些数据结构需要在最短的时间内访问。

只有几种方法马上想到的将是

某种动态分配的数组:


(1)void指针,必须强制转换为所需的类型。

(2)所需指针的联合。

(3)继承层次结构

(4)可能是所需数据类型的并集。


我需要能够构建任意数据结构

,其速度与建立在
$ b $的速度相同b编译时,但我需要在运行时这样做。


有没有人有什么好主意???

I want to be able to efficiently build data structures at run-time.
These data structures need to be accessed with minimal time.
The only a few ways that come immediately to mind would be
some sort of dynamically allocated array of :

(1) void pointers, that must be cast into the desired types.
(2) union of the desired pointers.
(3) An Inheritance hierarchy
(4) Possibly a union of the desired data types.

I need to be able to construct arbitrary data structures
that have as close to the same speed as those build at
compiler-time, yet I need to do this at run-time.

Does anyone have any good ideas ???

推荐答案

" Peter Olcott" <醇**** @ worldnet.att.net>在留言中写道

新闻:哦********************* @ bgtnsc04-news.ops.worldnet.att.net ...
"Peter Olcott" <ol****@worldnet.att.net> wrote in message
news:Oh*********************@bgtnsc04-news.ops.worldnet.att.net...
我希望能够在运行时有效地构建数据结构。


有助于了解您的目标,更大的图景。这是一个

语言运行时吗?

有多少动态结构在那儿?我一直在用我的语言玩堆栈

分配的对象,所以我有点想要你想要的东西。

这些数据结构需要在最短的时间内访问。
立即想到的几种方法将是某种动态分配的数组:

(1)void指针,必须转换为所需的类型。
(2)所需指针的并集。
(3)继承层次结构
(4)可能是所需数据类型的并集。

我需要能够构建任意数据结构,其速度与编译时生成的结构速度相同,但我需要在运行时执行此操作 - 时间。

有没有人有什么好主意???
I want to be able to efficiently build data structures at run-time.
It helps to know what you are trying to do, the bigger picture. Is this a
language runtime?

How many "dynamic structures" are there? I''ve been playing with stack
allocated objects in my language so I kind of have a feeling of what you
want.
These data structures need to be accessed with minimal time.
The only a few ways that come immediately to mind would be
some sort of dynamically allocated array of :

(1) void pointers, that must be cast into the desired types.
(2) union of the desired pointers.
(3) An Inheritance hierarchy
(4) Possibly a union of the desired data types.

I need to be able to construct arbitrary data structures
that have as close to the same speed as those build at
compiler-time, yet I need to do this at run-time.

Does anyone have any good ideas ???




取决于你真正想做的事情。


Mike



Depends on what you really want to do.

Mike


>我希望能够在运行时有效地构建数据结构。
> I want to be able to efficiently build data structures at run-time.
这些数据结构需要在最短的时间内访问。
立即想到的唯一几种方法是
某种动态分配的数组:

(1)void指针,必须强制转换为所需的类型。


是所需类型吗?在分配内存之前或之后已知?

动态分配的数组是否包含不同的类型?在

短,是否是多态的?

这些是所需类型吗? POD'或非POD'的?

有没有人有什么好主意?
These data structures need to be accessed with minimal time.
The only a few ways that come immediately to mind would be
some sort of dynamically allocated array of :

(1) void pointers, that must be cast into the desired types.
Are the "desired types" known before you allocate memory or after?
Can the dynamically allocated array contain different types or not? In
short, is it polymorphic or not?
Are these "desired types" POD''s or non-POD''s?
Does anyone have any good ideas ???




更准确地陈述你的问题。


Stephen Howe



State your problem more accurately.

Stephen Howe


我需要能够创建预先存在的类型的记录。在一些

的情况下,这些记录需要保存其他聚合,例如

作为向量,这些记录本身需要包含在

a向量中。


struct Test {

std :: vector< double> Test1;

float Test2;

std :: string Test3 [3];

};


std :: vector< Test> Test4;


结构可以是任何类型的组合,包括用户定义的

类型。结构是需要在运行时动态创建的结构。

最简单的方法可能是创建一个void的std :: vector,

然后转换这些在运行时进入所需类型,基于

存储在记录中的整数类型字段。我假设这个

演员花费了我的运行时间,如果可能的话我想避免。


" Vis Mike" < visionary25@_nospam_hotmail.com>在消息新闻中写道:be ********** @ bob.news.rcn.net ...
I need to be able to create records of pre-existing types. In some
cases these records would need to hold other aggregations, such
as vectors, and these records themselves need to be contained in
a vector.

struct Test {
std::vector<double> Test1;
float Test2;
std::string Test3[3];
};

std::vector<Test> Test4;

The struct can be any combination of types, including user defined
types. The struct is what needs to be dynamically created at run-time.
The simplest way might be to merely create a std::vector of void,
and then cast these into the desired types at run-time, based on
an integer type field stored in the record. I am assuming that this
cast costs me run-time, which I want to avoid if possible.

"Vis Mike" <visionary25@_nospam_hotmail.com> wrote in message news:be**********@bob.news.rcn.net...
" Peter Olcott" <醇**** @ worldnet.att.net>在消息中写道
新闻:哦********************* @ bgtnsc04-news.ops.worldnet.att.net ...
"Peter Olcott" <ol****@worldnet.att.net> wrote in message
news:Oh*********************@bgtnsc04-news.ops.worldnet.att.net...
我希望能够在运行时有效地构建数据结构。
I want to be able to efficiently build data structures at run-time.



它有助于了解您要做的事情,更大的图景。这是一个
语言运行时吗?

有多少动态结构在那儿?我一直在玩堆栈
用我的语言分配对象,所以我对你想要的东西感觉很好。



It helps to know what you are trying to do, the bigger picture. Is this a
language runtime?

How many "dynamic structures" are there? I''ve been playing with stack
allocated objects in my language so I kind of have a feeling of what you
want.

这些数据结构需要只需很短的时间即可访问。
立即想到的几种方法将是某种动态分配的数组:

(1)void指针,必须(2)所需指针的联合。
(3)继承层次结构
(4)可能是所需数据类型的联合。

我需要能够构建任意数据结构,其速度与编译时生成的结构速度接近,但我需要在运行时执行此操作。 br />
有没有人有什么好主意???
These data structures need to be accessed with minimal time.
The only a few ways that come immediately to mind would be
some sort of dynamically allocated array of :

(1) void pointers, that must be cast into the desired types.
(2) union of the desired pointers.
(3) An Inheritance hierarchy
(4) Possibly a union of the desired data types.

I need to be able to construct arbitrary data structures
that have as close to the same speed as those build at
compiler-time, yet I need to do this at run-time.

Does anyone have any good ideas ???



取决于你真正想做的事情。

迈克



Depends on what you really want to do.

Mike



这篇关于动态创建的结构???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆