sizeof

CUDA allocating array of arrays

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some trouble with allocate array of arrays in CUDA. void ** data; cudaMalloc(&data, sizeof(void**)*N); // allocates without problems for(int i = 0; i What did I wrong? 回答1: You have to allocate the pointers to a host memory, then allocate device memory for each array and store it's pointer in the host memory. Then allocate the memory for storing the pointers into the device and then copy the host memory to the device memory. One example is worth 1000 words: __global__ void multi_array_kernel( int N, void** arrays ){ // stuff } int

EnumDisplayDevices vs WMI Win32_DesktopMonitor, how to detect active monitors?

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For my current C++ project I need to detect a unique string for every monitor that is connected and active on a large number of computers. Research has pointed to 2 options Use WMI and query the Win32_DesktopMonitor for all active monitors. Use the PNPDeviceID for unique identification of monitors. Use the EnumDisplayDevices API, and dig down to get the device ID. I'm interested in using the device id for unique model identification because monitors using the default plug and play driver will report a generic string as the monitor name

Delphi: How to start application with elevated status and wait for it to terminate?

匿名 (未验证) 提交于 2019-12-03 01:09:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to start another application from my program with elevated rights, and wait for it to terminate before continuing. I've tried several different solutions on the web, but I can't find one that works exactly right. The code below is the closest I have to working right. It runs the app with elevated privileges and waits for it to terminate, but it freezes once the external app is terminated. In other words, it doesn't keep processing once the launched app is closed. How can I accomplish what I'm after here? procedure TfMain

strncpy doesn't always null-terminate

匿名 (未验证) 提交于 2019-12-03 01:09:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using the code below: char filename[ 255 ]; strncpy( filename, getenv( "HOME" ), 235 ); strncat( filename, "/.config/stationlist.xml", 255 ); Get this message: (warning) Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append. (error) Dangerous usage of 'filename' (strncpy doesn't always null-terminate it). 回答1: I typically avoid using str*cpy() and str*cat() . You have to contend with boundary conditions, arcane API definitions, and unintended performance consequences. You can use snprintf() instead.

How do I merge two arrays having different values into one array?

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Suppose you have one array a[]=1,2,4,6 and a second array b[]=3,5,7 . The merged result should have all the values, i.e. c[]=1,2,3,4,5,6,7 . The merge should be done without using functions from . 回答1: I haven't compiled and tested the following code, but I am reasonably confident. I am assuming both input arrays are already sorted. There is more work to do to make this general purpose as opposed to a solution for this example only. No doubt the two phases I identify could be combined, but perhaps that would be harder to read and verify;

Can a const variable be used to declare the size of an array in C?

匿名 (未验证) 提交于 2019-12-03 01:07:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why does the following code throw an error? const int a = 5; int b[a]={1,2,3,4,5}; And also when I tried to compile the above code without "const" keyword, I got the same error: int a = 5; int b[a]={1,2,3,4,5}; why is it so? What is the mistake that I am doing here? And also another question: When are constants replaced with their actual values in a code, i.e if I declare a variable say: const int x= 5; I know that no memory is allocated in RAM for the variable x, but constant variable area in ROM holds the value 5 and that x is simply

Is it safe to reinterpret_cast an integer to float?

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Note: I mistakenly asked about static_cast originally; this is why the top answer mentions static_cast at first. I have some binary files with little endian float values. I want to read them in a machine-independent manner. My byte-swapping routines (from SDL) operate on unsigned integers types. Is it safe to simply cast between ints and floats? float read_float() { // Read in 4 bytes. Uint32 val; fread( &val, 4, 1, fp ); // Swap the bytes to little-endian if necessary. val = SDL_SwapLE32(val); // Return as a float return reinterpret_cast (

Does the argument list pass the string quotes to exec command in C?

匿名 (未验证) 提交于 2019-12-03 01:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using execvp for execing a new process for the command grep -l night * . Here is my code: char * argument [ 5 ]; char keyword [] = "night" ; argument [ 0 ] = ( char *) malloc ( sizeof ( char )* 25 ); argument [ 1 ] = ( char *) malloc ( sizeof ( char )* 25 ); argument [ 2 ] = ( char *) malloc ( sizeof ( char )* 25 ); argument [ 3 ] = ( char *) malloc ( sizeof ( char )* 25 ); argument [ 4 ] = ( char *) malloc ( sizeof ( char )* 25 ); argument [ 0 ] = "grep" ; argument [ 1 ] = "-l" ; strcpy ( argument [ 2 ], keyword ); argument [

Creating and binding socket on Mac OS Hight Sierra

匿名 (未验证) 提交于 2019-12-03 01:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have serious and strange problem with creating socket in my application for Hight Sierra. If I create command Line tool, everything is ok! I create socket, bind socket. But If I trying to create Cocoa App, I can't binding my socket! :( If I use CFSockets in Cocoa App, char punchline[] = "MESSAGE from Server!"; int yes = 1; CFSocketContext CTX = {0, punchline, NULL, NULL, NULL}; CFSocketRef TCPServer = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, (CFSocketCallBack) &AcceptCallBack, &CTX);

How to change master volume programmatically?

匿名 (未验证) 提交于 2019-12-03 01:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In C/C++ on windows xp how to get master volume or how to change master volume...? Thanks in advance... 回答1: The starting point for API documentation in the MSDN library would be here . Helpful code can be found by searching for MIXERCONTROL_CONTROLTYPE_VOLUME , yielding code like this (taken from here ) static const unsigned MAXIMUM_VOLUME_LEVEL_DEFINED_BY_USER = 100; Win32VolumeControl::Win32VolumeControl(const AudioDevice & audioDevice) { std::string deviceName = audioDevice.getData()[0]; //String deviceId = audioDevice.getData()[1];