标签: structure

推荐使用JavaScript中的命名空间技术?高性能?需要注意的问题?

在我正在研究的项目中,我正在构建我的代码,如下所示

MyLib = {
    AField:0,

    ASubNamespace:{
        AnotherField:"value",

        AClass:function(param) {
            this.classField = param;

            this.classFunction = function(){
                // stuff
            }
        }
    },

    AnotherClass:function(param) {
        this.classField = param;

        this.classFunction = function(){
            // stuff
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

等等做这样的事情:

var anInstance = new MyLib.ASubNamespace.AClass("A parameter.");
Run Code Online (Sandbox Code Playgroud)

这是实现命名空间的正确方法吗?是否有性能命中,如果有,有多激烈?当我嵌套更深时,性能降级是否堆叠?使用此结构时是否还有其他问题需要注意?

我关心每一点性能,因为它是一个实时图形库,所以我非常重视任何开销.

javascript namespaces structure

4
推荐指数
1
解决办法
1421
查看次数

Python ctypes - 接受结构崩溃的dll函数

我必须访问ms windows xp下的POS终端.我正在使用python 2.7.我负载的DLL中的关键功能是支付接受两个结构指针,但它崩溃返回1(通信错误)但没有进一步的消息.请注意,调用支付函数时,并非POSData结构的所有元素都会收到值.我尝试的其他功能(GetVersion)确实有效.这里的规格和我的代码:

typedef struct
{
  char IPAddress[16]; //xxx.xxx.xxx.xxx
  int Port;
} TETHParameters;   
typedef struct
{
  char TerminalId[8+1];
  char AcquirerId[11+1];
  char TransactionType[3+1];
  char TransactionResult[2+1];
  char KODescription[24+1];
  char CardType[1+1];
  char STAN[6+1];
  char PAN[19+1];
  char AuthorizationCode[6+1];
  char OperationNumber[6+1];
  char DataTrs[7+1];
} TPOSData;

typedef struct
{
  char Amount[8+1];
  char ECRId[8+1];
  char PaymentType[1+1];
  char TerminalId[8+1];
} TECRData;

__declspec(dllexport) void IAE17_GetVersion(char *Version);
__declspec(dllexport) void IAE17_InitEth(TETHParameters *ETHParameters);

__declspec(dllexport) void IAE17_Free(void);

__declspec(dllexport) int IAE17_Payment(TECRData *ECRData, TPOSData *POSData);
Run Code Online (Sandbox Code Playgroud)
from ctypes import *
#da python 3.x sara' configparser …
Run Code Online (Sandbox Code Playgroud)

python ctypes pointers structure

4
推荐指数
1
解决办法
1856
查看次数

在Windows窗体应用程序中永远循环

我正在使用Visual C#sand我使用的是Windows窗体而不是控制台应用程序.因此,我不是在Main()中工作,而是在Form File中工作.我对C#也很陌生,所以如果我的一些问题是愚蠢的,那就很抱歉.

我基本上需要做的是当我的程序启动时我需要它来永远循环.因为我没有Main(),所以我会把这段代码放在哪里?我把它放在有InitializeComponent()的函数中吗?我需要在程序启动后立即启动循环.但是,我需要在循环之前首先声明一些变量.所以基本上我需要声明变量然后开始无限循环.变量是全球性的.

其次,当用户按下按钮时,我需要无限循环中断.我该怎么做?我在考虑以下几点:

while (buttonIsPressed == false)
{
   //do whatever I need to do
}
Run Code Online (Sandbox Code Playgroud)

但是,我意识到按钮的功能永远不会被调用,因为我被困在那个循环中.如果由于处于无限循环中而从未到达按钮的功能,我无法从按钮的功能设置变量.有任何想法吗?我在思考线程,但我对线程没有任何经验,所以我有点不愿意尝试它.


另外,来自评论:

聊天应用程序.程序启动时我需要它继续听.但是,当用户单击"连接"时,它会停止侦听,而是启动连接

我正在创建一个聊天客户端.所以基本上当我的程序启动时,我需要它继续听.但是,当用户单击"连接"时,它需要停止侦听,而是启动连接

c# loops structure

4
推荐指数
1
解决办法
4万
查看次数

为什么结构不能包含自身的实例?

我读到了c ++中的结构,它不能包含自身的实例.任何人都可以帮助我理解为什么它不能包含自身的实例?

c++ structure

4
推荐指数
3
解决办法
4962
查看次数

Java - 强制实现已实现的方法

我有三个课我遇到问题.它们被命名为:GameScene,StageScene,StageOne.我的问题是我想在StageScene中实现初始化,但仍然强制StageOne实现它,这样每当有人使用StageOne对象(stageOne.initialize())时,将为StageScene和StageOne运行初始化.任何人都知道如何做到这一点?

public abstract class GameScene 
{
    public abstract void initialize();
}

public abstract class StageScene extends GameScene
{
    public abstract void initialize()
    {
        //Some code
    }
}
public class StageOne extends StageScene
{
    public void initialize()
    {
        //Some code
    }
}
Run Code Online (Sandbox Code Playgroud)

java methods inheritance structure abstract

4
推荐指数
1
解决办法
3015
查看次数

在.net结构构造函数中使用try-catch

我需要一个.net结构(它模仿连接的设备内部映射),我想使用try catch块,因为我使用Marshall.PtrToStructure()和相关的GChandle东西.但是,当我在try catch块中放置结构字段赋值时,我得到此错误"必须在控制权返回给发件人之前完全分配field1".没有try catch块,基本代码工作正常.使用try catch块时是否有任何解决此错误的方法?我应该使用try catch吗?

[StructLayout( LayoutKind.Sequential )]
public struct Effects
{
    public UInt16 field_1;
    public UInt16 field_2;
    ...



    public Effects(byte[] effectsData)
    {
       GCHandle gch;
       try
       {
           gch = GCHandle.Alloc( effectsData, GCHandleType.Pinned );
           IntPtr pEffects = gch.AddrOfPinnedObject( );
           this = (Effects)Marshal.PtrToStructure( pEffects, typeof(Effects ) );
       }
       catch (Exception ex)
       {

       }
       finally
       {
           if (gch.IsAllocated)
               gch.Free( );
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# structure try-catch

4
推荐指数
1
解决办法
3172
查看次数

C中结构的详细信息

我是C的新手.我在googled很多关于下面代码的输出.但没有太大的帮助.

这是代码:

struct str
{
    int i: 1;
    int j: 2;
    int k: 3;
    int l: 4;
};

struct str s;

s.i = 1;
s.j = 2;
s.k = 5;
s.l = 10;

printf(" i: %d \n j: %d \n k: %d \n l: %d \n", s.i, s.j, s.k, s.l);
Output:
i: -1
j: -2
k: -3
l: -6
Run Code Online (Sandbox Code Playgroud)

谁能解释为什么输出如此?谢谢.

c structure

4
推荐指数
1
解决办法
170
查看次数

C,从文件读入结构

几天来我一直在努力奋斗,我无法弄清楚为什么它不起作用.

我正在尝试从文件中读取带有这样的数字的数字:

0 2012 1 1 2000.000000
0 2012 1 1 3000.000000
1 2012 1 1 4500.000000
Run Code Online (Sandbox Code Playgroud)

我的结构:

struct element{

        int id;
        int sign;
        int year;
        int month;
        double amount;

        struct element *next;


};

struct queue{
    struct element *head;
    struct element *tail;
    struct element *head2; 
    struct element *temp;  
    struct element *temph; 

    int size;
};
Run Code Online (Sandbox Code Playgroud)

(head2,temp和temph用于排序结构)

并从文件中读取:

void read_str(struct queue *queue){

    FILE *reads;

    char filename[40];
    int temp;

    printf("Type in name of the file\n");
    scanf("%s",&filename);
    reads=fopen(filename, "r");
    if (reads==NULL) {
        perror("Error");
        return …
Run Code Online (Sandbox Code Playgroud)

c structure file

4
推荐指数
1
解决办法
6万
查看次数

在C中具有指针作为成员的结构的memcpy

如果这是一个愚蠢的问题,请不要投票给我,我只是想了解.

我有一个结构,有一些指针作为成员,我正在尝试做memcpy,我有人建议我不应该在这种情况下使用memcpy作为memcpy做一个浅拷贝(意思是它复制指针)相当深的拷贝(意味着复制什么指针)指向).

但我不确定为什么它在以下程序中没有任何区别:请查看代码和输出,并解释为什么在这种情况下它不是浅层副本?

#include <stdio.h>
#include <malloc.h>
#include <string.h>

struct student {
    char *username;
    char *id;
    int roll;
};

void print_struct(struct student *);
void print_struct_addr(struct student *);
void changeme(struct student *);

int main (void) {
    struct student *student1;
    char *name = "ram";
    char *id = "200ABCD";
    int roll = 34;

    student1 = (struct student *)malloc(sizeof(struct student));
    student1->username = name; 
    student1->id = id;
    student1->roll = roll; 
    print_struct_addr(student1);
    print_struct(student1);
    changeme(student1);
    print_struct(student1);
    print_struct_addr(student1);
    return 0;
}

void print_struct(struct student *s) {
    printf("Name: %s\n", …
Run Code Online (Sandbox Code Playgroud)

c structure data-structures

4
推荐指数
2
解决办法
1万
查看次数

在Liferay中获取具有特定结构的Web内容文章

我已经开始使用Liferay开发portlet,我想展示一个(或更多)具有指定结构的Web内容文章.

例如,假设我有一个结构"A",那么如何才能获得使用此结构创建的最后一篇Web内容文章?

文章介绍了如何得到一个物品tag,但不能用structure.

谢谢

portlet structure web-content liferay

4
推荐指数
1
解决办法
4736
查看次数