sizeof

Efficiently load a large Mat into memory in OpenCV

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a more efficient way to load a large Mat object into memory than the FileStorage method in OpenCV? I have a large Mat with 192 columns and 1 million rows I want to store locally in a file and load into memory then my application starts. There is no problem using the FileStorage, but I was wondering if there exists a more efficient method to do this. At the moment it takes about 5 minutes to load the Mat into memory using the Debug mode in Visual Studio and around 3 minutes in the Release mode and the size of the data file is around

What is CHAR_BIT?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Quoting the code for computing the integer absolute value (abs) without branching from http://graphics.stanford.edu/~seander/bithacks.html : int v; // we want to find the absolute value of v unsigned int r; // the result goes here int const mask = v >> sizeof(int) * CHAR_BIT - 1; r = (v + mask) ^ mask; Patented variation: r = (v ^ mask) - mask; What is CHAR_BIT and how use it? 回答1: You should be aware that this code depends on the implementation-defined behavior of right bitshift on signed types. gcc promises to always give the sane behavior

invalid application of 'sizeof' to incomplete type list struct C

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to implement an replacement algorithm that deals with page faults. So i'm trying to creat a circular linked list using malloc and im getting the following error: "invalid application of sizeof' to incomplete type pageInMemory'.following is the code: typedef struct { int use; int reference; int free; struct pageInMemory* next; } pageInMemory; int main() { int i; struct pageInMemory* start, *nn, *temp, *hand; start = NULL; for(i=0; i< pNum; i++) { nn = (struct pageInMemory *)malloc(sizeof(struct pageInMemory)); nn->use = 0; nn->free

“&#039;void*&#039; is not a pointer-to-object type” in code with no void*&#039;s?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a problem in my code. In Xcode or using the C++11 compiler, this code works well. However, when I am submitting this code to an Online Judge, the verdict shows "Compile Error" . I think they use the C++4.7.1 compiler, which when I tried to compile it (using Ideone), it says: prog.cpp: In function 'void printArray(int)': prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a

Strict alias violation or alignment violation with a struct with flexible array member?

匿名 (未验证) 提交于 2019-12-03 01:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Imagine a structure like this: struct test_s { int i ; size_t namelen ; char name []; }; Now I would like to return an array of such structures to user code, also using a generic function which takes a void * pointer: size_t test_read ( void * buf , size_t bufsize ); Each of the array elements would need to aligned to struct s_s alignment. In each of array element the namelen is adjusted, so it is greater or equal then strlen(name) , but with additional "unused" bytes in between array members, so that next array member starts at

Empty structure in C

匿名 (未验证) 提交于 2019-12-03 01:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a structure with no members (for the moment) and I would like to know if it is possible to suppress the warning I get: warning: struct has no members Is it possible to add a member and keep the sizeof the struct zero? Any other solution? 回答1: In c the behaviour of an empty structure is compiler dependent versus c++ where it is part of the spec ( explanations here ) C++ A class with an empty sequence of members and base class objects is an empty class. Complete objects and member subobjects of an empty class type shall have nonzero

Enforce template type through static_assert

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to understand the usefulness of static_assert , and I want to know if it can help me in enforcing a design, and if so, how. I have a general template class that hides its own implementation inside another template class which is partially specialized based on the size of the template type. Here's a brief outline of this design: template < class T , size_t S = sizeof ( T )> struct Helper ; template < class T > struct Helper < T , sizeof ( long )> { static T bar (); }; // ... other specializations ... template < class T >

Use RegisterDeviceNotification() for ALL USB devices

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I currently have some code that sets up notifications of connected USB HID devices within a Windows Service (written in C++). The code is as follows: GUID hidGuid; HidD_GetHidGuid(&hidGuid); DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; ZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; NotificationFilter.dbcc_classguid = hidGuid; HDEVNOTIFY deviceNotify = RegisterDeviceNotification(StatusHandle

sizeof applied to the name of an array vs a pointer to the first element of the array

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Suppose I declare int v[]={1,2,3,4,5}; I have been taught that v is a pointer to the first element in the v array. When I call apply sizeof to v , it returns 20, which I know is 5*sizeof(int) , because there are 5 elements in the array. v+0 is also a pointer to the first element in the array, but sizeof(v+0) is 4. Why is sizeof(v) =20 and sizeof(v+0) =4? I would expect that sizeof(v) also returned 4, as v is a pointer, but instead it somehow also contains the information regarding the number of elements stored in the array. What is

c++ sizeof() of a class with functions

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a C++ question. I wrote the following class: class c { int f ( int x , int y ){ return x ; } }; the sizeof() of class c returns "1". I I really don't understand why it returns 1. Trying to understand better what is going on, I added another function: class c { int f ( int x , int y ){ return x ; } int g ( int x , int y ){ return x ; } }; Now the following really got me confused! sizeof(c) is still 1 (!?!?!?!). So I guess that functions doesn't change the size of the class, but why??? and why does the size is 1 ? And is it