struct

Process control block in Linux

我怕爱的太早我们不能终老 提交于 2021-02-07 18:14:19
问题 How to extract PCB in linux? or Is there any kernel module available to read it? 回答1: The closest Linux equivalent is the task_struct ; however, that's only used inside the kernel. It's not exported to userspace. All information on running processes on Linux is exposed via procfs , which is mounted at /proc . See man proc for details on what's available and where. 来源: https://stackoverflow.com/questions/8162956/process-control-block-in-linux

Process control block in Linux

岁酱吖の 提交于 2021-02-07 18:03:12
问题 How to extract PCB in linux? or Is there any kernel module available to read it? 回答1: The closest Linux equivalent is the task_struct ; however, that's only used inside the kernel. It's not exported to userspace. All information on running processes on Linux is exposed via procfs , which is mounted at /proc . See man proc for details on what's available and where. 来源: https://stackoverflow.com/questions/8162956/process-control-block-in-linux

Why does an array of classes consume ~20% more memory than array of structs?

佐手、 提交于 2021-02-07 13:36:53
问题 I'm making a 2D platformer game and to represent a level I'm using 2D array of tiles which are classes with fields for position, type and various flags. When I change the class key word in the tile class to struct , a loaded map consumes about 20% less memory. I don't know about rights and wrongs of this action, I just want to know why the difference in memory consumption. Edit: numbers are 1038 MB with tiles as classes and 845 MB as structs (without most of game data). 回答1: An array of

How to set structure element at desired offset

╄→гoц情女王★ 提交于 2021-02-07 13:34:58
问题 In embedded programming when describing the hardware one often needs to place struct elements at known predefined positions as the HW engineer designed them. For example, let's define a structure FPGA, which has some 100 registers/areas as in the following simplified example: struct __attribute__ ((__packed__)) sFPGA { uchar Spare1[0x24]; ushort DiscreteInput; uchar Spare2[0x7A]; //CPLD_Version is required to be at offset 0xA0, so 0xA0-0x24-2=0x7A ushort CPLD_Version; }; Now, I am frustrated

How to set structure element at desired offset

可紊 提交于 2021-02-07 13:33:27
问题 In embedded programming when describing the hardware one often needs to place struct elements at known predefined positions as the HW engineer designed them. For example, let's define a structure FPGA, which has some 100 registers/areas as in the following simplified example: struct __attribute__ ((__packed__)) sFPGA { uchar Spare1[0x24]; ushort DiscreteInput; uchar Spare2[0x7A]; //CPLD_Version is required to be at offset 0xA0, so 0xA0-0x24-2=0x7A ushort CPLD_Version; }; Now, I am frustrated

How to set structure element at desired offset

风流意气都作罢 提交于 2021-02-07 13:32:35
问题 In embedded programming when describing the hardware one often needs to place struct elements at known predefined positions as the HW engineer designed them. For example, let's define a structure FPGA, which has some 100 registers/areas as in the following simplified example: struct __attribute__ ((__packed__)) sFPGA { uchar Spare1[0x24]; ushort DiscreteInput; uchar Spare2[0x7A]; //CPLD_Version is required to be at offset 0xA0, so 0xA0-0x24-2=0x7A ushort CPLD_Version; }; Now, I am frustrated

Writing a 'generic' struct-print method in C

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-07 11:15:16
问题 Is it possible to do something like the following in C, to print a different-but-similar struct type? #include<stdio.h> typedef struct Car { char* name; unsigned int cost } Car; typedef struct Animal { char* name; unsigned int age; unsigned int weight } Animal; void print_struct(void *obj) { printf("The name is: %s\n", obj->name); }; int main(void) { Animal *dog = & (Animal) {.name = "Dog", .age = 10, .weight = 200}; Car *ford = & (Car) {.name = "Ford", .cost = 50000}; print_struct(dog); };

Writing a 'generic' struct-print method in C

99封情书 提交于 2021-02-07 11:06:27
问题 Is it possible to do something like the following in C, to print a different-but-similar struct type? #include<stdio.h> typedef struct Car { char* name; unsigned int cost } Car; typedef struct Animal { char* name; unsigned int age; unsigned int weight } Animal; void print_struct(void *obj) { printf("The name is: %s\n", obj->name); }; int main(void) { Animal *dog = & (Animal) {.name = "Dog", .age = 10, .weight = 200}; Car *ford = & (Car) {.name = "Ford", .cost = 50000}; print_struct(dog); };

How to parse string to struct?

好久不见. 提交于 2021-02-07 10:18:26
问题 I want to know if there is any way to convert a string like "5ABBF13A000A01" to the next struct using struct and union method: struct xSensorData2{ unsigned char flags; unsigned int refresh_rate; unsigned int timestamp; }; Data should be: flags = 0x01 (last byte); refresh_rate = 0x000A (two bytes); timestamp = 5ABBF13A (four bytes); I'm thinking in next struct of data: struct xData{ union{ struct{ unsigned char flags:8; unsigned int refresh_rate:16; unsigned int timestamp:32; }; char pcBytes

How to parse string to struct?

橙三吉。 提交于 2021-02-07 10:16:39
问题 I want to know if there is any way to convert a string like "5ABBF13A000A01" to the next struct using struct and union method: struct xSensorData2{ unsigned char flags; unsigned int refresh_rate; unsigned int timestamp; }; Data should be: flags = 0x01 (last byte); refresh_rate = 0x000A (two bytes); timestamp = 5ABBF13A (four bytes); I'm thinking in next struct of data: struct xData{ union{ struct{ unsigned char flags:8; unsigned int refresh_rate:16; unsigned int timestamp:32; }; char pcBytes