Why is there memory leaks with SDL2 (2.0.14) dll? - c
I am using SDL2 version 2.0.14. This is the current stable version.
I noticed that any program I write with SDL2 has memory leaks. For example
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("title",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_OPENGL);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
This is the main.c file. I build it with gcc main.c -o main.exe -lSDL2 -lSDL2main
If I run drmemory main.exe this is what I get -
ERRORS FOUND:
1 unique, 2 total unaddressable access(es)
6 unique, 6 total uninitialized access(es)
0 unique, 0 total invalid heap argument(s)
0 unique, 0 total GDI usage error(s)
0 unique, 0 total handle leak(s)
0 unique, 0 total warning(s)
1 unique, 1 total, 88 byte(s) of leak(s)
1 unique, 1 total, 26 byte(s) of possible leak(s)
I don't see why this program has leaks at all. I tried to find out what is wrong and came across this question
Although this is already answered, I don't see how this solves my issue. I want to know why am I having these leaks and how to fix them. Also do I need to worry about those unaddressable and uninitialized accesses diagnosed by Dr. Memory.
I suspect it has to do something with the SDL2.dll I downloaded from SDL2. I am using the win32-x64 dll.
EDIT
Here is the full 'error' details
Dr. Memory version 2.3.0 build 1 built on Feb 6 2020 06:07:09
Windows version: WinVer=63;Rel=;Build=9600;Edition=Professional
Dr. Memory results for pid 4868: "main.exe"
Application cmdline: "main.exe"
Recorded 118 suppression(s) from default C:\Program Files (x86)\Dr. Memory\bin64\suppress-default.txt
Error #1: UNADDRESSABLE ACCESS beyond top of stack: reading 0x000000000023fb70-0x000000000023fb78 8 byte(s)
# 0 .text [../../../../../src/gcc-8.1.0/libgcc/config/i386/cygwin.S:132]
# 1 _pei386_runtime_relocator
# 2 __tmainCRTStartup
# 3 .l_start
# 4 KERNEL32.dll!BaseThreadInitThunk +0x21 (0x00007ff902e81412 <KERNEL32.dll+0x1412>)
Note: #0:00:00.281 in thread 3800
Note: 0x000000000023fb70 refers to 600 byte(s) beyond the top of the stack 0x000000000023fdc8
Note: instruction: or $0x0000000000000000 (%rcx) -> (%rcx)
Error #2: UNINITIALIZED READ: reading 0x000000000023eeec-0x000000000023eef0 4 byte(s) within 0x000000000023eee8-0x000000000023eef0
# 0 system call NtGdiOpenDCW parameter value #5
# 1 GDI32.dll!GetNearestColor +0x21f (0x00007ff903152650 <GDI32.dll+0x12650>)
# 2 GDI32.dll!GetNearestColor +0x30c (0x00007ff90315273d <GDI32.dll+0x1273d>)
# 3 GDI32.dll!CreateDCW +0x12 (0x00007ff903152783 <GDI32.dll+0x12783>)
# 4 SDL2.dll!? +0x0 (0x0000000073eae403 <SDL2.dll+0x10e403>)
# 5 SDL2.dll!? +0x0 (0x0000000073eae781 <SDL2.dll+0x10e781>)
# 6 USER32.dll!mouse_event +0x1f9 (0x00007ff90532df1a <USER32.dll+0xdf1a>)
# 7 SDL2.dll!? +0x0 (0x0000000073eae91a <SDL2.dll+0x10e91a>)
# 8 SDL2.dll!? +0x0 (0x0000000073eb1d9d <SDL2.dll+0x111d9d>)
# 9 SDL2.dll!? +0x0 (0x0000000073e760ce <SDL2.dll+0xd60ce>)
#10 SDL2.dll!? +0x0 (0x0000000073da1547 <SDL2.dll+0x1547>)
#11 main
Note: #0:00:02.451 in thread 3800
Error #3: UNINITIALIZED READ: reading 0x000000000023f734-0x000000000023f738 4 byte(s) within 0x000000000023f730-0x000000000023f738
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eaffe9 <SDL2.dll+0x10ffe9>)
# 5 SDL2.dll!? +0x0 (0x0000000073eb08fc <SDL2.dll+0x1108fc>)
# 6 SDL2.dll!? +0x0 (0x0000000073e740b7 <SDL2.dll+0xd40b7>)
# 7 SDL2.dll!? +0x0 (0x0000000073e755df <SDL2.dll+0xd55df>)
# 8 main
Note: #0:00:02.839 in thread 3800
Error #4: UNINITIALIZED READ: reading 0x000000000023f7d4-0x000000000023f7d8 4 byte(s) within 0x000000000023f7d0-0x000000000023f7d8
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eb2b9c <SDL2.dll+0x112b9c>)
# 5 SDL2.dll!? +0x0 (0x0000000073e7584d <SDL2.dll+0xd584d>)
# 6 main
Note: #0:00:03.636 in thread 3800
Error #5: UNINITIALIZED READ: reading 0x000000000023f494-0x000000000023f498 4 byte(s) within 0x000000000023f490-0x000000000023f498
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eaf7fa <SDL2.dll+0x10f7fa>)
# 5 SDL2.dll!? +0x0 (0x0000000073eafaed <SDL2.dll+0x10faed>)
# 6 SDL2.dll!? +0x0 (0x0000000073eb099d <SDL2.dll+0x11099d>)
# 7 SDL2.dll!? +0x0 (0x0000000073eb2c5b <SDL2.dll+0x112c5b>)
# 8 SDL2.dll!? +0x0 (0x0000000073e7584d <SDL2.dll+0xd584d>)
# 9 main
Note: #0:00:03.890 in thread 3800
Error #6: UNINITIALIZED READ: reading 0x000000000023f494-0x000000000023f498 4 byte(s) within 0x000000000023f490-0x000000000023f498
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eaf7fa <SDL2.dll+0x10f7fa>)
# 5 SDL2.dll!? +0x0 (0x0000000073eafe55 <SDL2.dll+0x10fe55>)
# 6 SDL2.dll!? +0x0 (0x0000000073eb099d <SDL2.dll+0x11099d>)
# 7 SDL2.dll!? +0x0 (0x0000000073eb2c5b <SDL2.dll+0x112c5b>)
# 8 SDL2.dll!? +0x0 (0x0000000073e7584d <SDL2.dll+0xd584d>)
# 9 main
Note: #0:00:03.947 in thread 3800
Error #7: UNINITIALIZED READ: reading 0x000000000023f6b0-0x000000000023f6b8 8 byte(s) within 0x000000000023f6a8-0x000000000023f6b8
# 0 system call NtUserTrackMouseEvent TRACKMOUSEEVENT post-dwFlags
# 1 SDL2.dll!? +0x0 (0x0000000073eb3bf2 <SDL2.dll+0x113bf2>)
# 2 SDL2.dll!? +0x0 (0x0000000073dcc1b7 <SDL2.dll+0x2c1b7>)
# 3 SDL2.dll!? +0x0 (0x0000000073dca237 <SDL2.dll+0x2a237>)
# 4 SDL2.dll!? +0x0 (0x0000000073dca7a8 <SDL2.dll+0x2a7a8>)
# 5 SDL2.dll!? +0x0 (0x0000000073ea90d8 <SDL2.dll+0x1090d8>)
# 6 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
# 7 USER32.dll!DispatchMessageW +0xc2 (0x00007ff905322463 <USER32.dll+0x2463>)
# 8 USER32.dll!CallWindowProcW +0x9a (0x00007ff905323ccb <USER32.dll+0x3ccb>)
# 9 OPENGL32.dll!glDebugEntry +0x1146b (0x00007ff8fa3928fc <OPENGL32.dll+0x428fc>)
#10 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
#11 USER32.dll!DispatchMessageW +0xc2 (0x00007ff905322463 <USER32.dll+0x2463>)
#12 USER32.dll!MsgWaitForMultipleObjects +0x141 (0x00007ff905323902 <USER32.dll+0x3902>)
#13 USER32.dll!MsgWaitForMultipleObjects +0x20d (0x00007ff9053239ce <USER32.dll+0x39ce>)
#14 USER32.dll!GetWindowLongW +0x10f (0x00007ff905326980 <USER32.dll+0x6980>)
#15 SDL2.dll!? +0x0 (0x0000000073e73b3c <SDL2.dll+0xd3b3c>)
#16 SDL2.dll!? +0x0 (0x0000000073e75896 <SDL2.dll+0xd5896>)
#17 main
Note: #0:00:06.599 in thread 3800
Error #8: LEAK 88 direct bytes 0x0000000002679b00-0x0000000002679b58 + 0 indirect bytes
# 0 replace_RtlAllocateHeap [d:\drmemory_package\common\alloc_replace.c:3771]
# 1 IMM32.dll!CtfImmGetTMAEFlags +0x1b4 (0x00007ff905013b35 <IMM32.dll+0x3b35>)
# 2 IMM32.dll!ImmGetContext +0x105 (0x00007ff905012396 <IMM32.dll+0x2396>)
# 3 SDL2.dll!? +0x0 (0x0000000073eaae90 <SDL2.dll+0x10ae90>)
# 4 SDL2.dll!? +0x0 (0x0000000073eab89b <SDL2.dll+0x10b89b>)
# 5 SDL2.dll!? +0x0 (0x0000000073dc8961 <SDL2.dll+0x28961>)
# 6 SDL2.dll!? +0x0 (0x0000000073ea90a4 <SDL2.dll+0x1090a4>)
# 7 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
# 8 USER32.dll!DispatchMessageW +0xc2 (0x00007ff905322463 <USER32.dll+0x2463>)
# 9 USER32.dll!CallWindowProcW +0x9a (0x00007ff905323ccb <USER32.dll+0x3ccb>)
#10 OPENGL32.dll!glDebugEntry +0x1146b (0x00007ff8fa3928fc <OPENGL32.dll+0x428fc>)
#11 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
Error #9: POSSIBLE LEAK 26 direct bytes 0x00000000029c01c0-0x00000000029c01da + 0 indirect bytes
# 0 replace_malloc [d:\drmemory_package\common\alloc_replace.c:2577]
# 1 msvcrt.dll!malloc_crt
# 2 msvcrt.dll!_setargv
# 3 msvcrt.dll!_getmainargs
# 4 pre_cpp_init
# 5 msvcrt.dll!initterm
# 6 __tmainCRTStartup
# 7 .l_start
# 8 KERNEL32.dll!BaseThreadInitThunk +0x21 (0x00007ff902e81412 <KERNEL32.dll+0x1412>)
===========================================================================
FINAL SUMMARY:
DUPLICATE ERROR COUNTS:
Error # 1: 2
SUPPRESSIONS USED:
ERRORS FOUND:
1 unique, 2 total unaddressable access(es)
6 unique, 6 total uninitialized access(es)
0 unique, 0 total invalid heap argument(s)
0 unique, 0 total GDI usage error(s)
0 unique, 0 total handle leak(s)
0 unique, 0 total warning(s)
1 unique, 1 total, 88 byte(s) of leak(s)
1 unique, 1 total, 26 byte(s) of possible leak(s)
ERRORS IGNORED:
91 potential error(s) (suspected false positives)
(details: C:\Users\Kabir\AppData\Roaming\Dr. Memory\DrMemory-main.exe.4868.000\potential_errors.txt)
10 potential leak(s) (suspected false positives)
(details: C:\Users\Kabir\AppData\Roaming\Dr. Memory\DrMemory-main.exe.4868.000\potential_errors.txt)
112 unique, 248 total, 34288 byte(s) of still-reachable allocation(s)
(re-run with "-show_reachable" for details)
Details: C:\Users\Kabir\AppData\Roaming\Dr. Memory\DrMemory-main.exe.4868.000\results.txt
Related
Check if array index is out of range in Dr Memory
I need to check if an array index is out of range by using Dr.Memory. I don't use dynamic memory allocation in this case. When I check this code with Dr.Memory. I'm using Windows 11. int main() { clock_t start, end; float cpu_time_used; start = clock(); int array[5] = {2, 4, 5, 6, 7}; int number = array[10]; printf("This is a number: %i\n", number); end = clock(); cpu_time_used = ((float) (end - start)) / CLOCKS_PER_SEC; printf("\nTotal speed was %f\n", cpu_time_used); return EXIT_SUCCESS; } I get this output from Dr.Memory. As you can see, no complaining about that the index is out of range. Why? Dr. Memory version 2.5.0 build 0 built on Oct 18 2021 03:01:22 Windows version: WinVer=105;Rel=2009;Build=22000;Edition=Professional Dr. Memory results for pid 9640: "CControl.exe" Application cmdline: ""C:\Users\dmn\OneDrive - ITH\Dokument\Projekt\Eclipse\CControl\Debug\CControl.exe"" Recorded 124 suppression(s) from default C:\Program Files (x86)\Dr. Memory\bin64\suppress-default.txt Error #1: UNADDRESSABLE ACCESS beyond top of stack: reading 0x000000164a9ff980-0x000000164a9ff988 8 byte(s) # 0 ___chkstk_ms [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:132] # 1 _pei386_runtime_relocator # 2 __tmainCRTStartup # 3 .l_start # 4 ntdll.dll!RtlUserThreadStart Note: #0:00:00.097 in thread 18604 Note: 0x000000164a9ff980 refers to 664 byte(s) beyond the top of the stack 0x000000164a9ffc18 Note: instruction: or $0x0000000000000000 (%rcx) -> (%rcx) Error #2: UNADDRESSABLE ACCESS beyond top of stack: reading 0x000000164a9ffa50-0x000000164a9ffa58 8 byte(s) # 0 ___chkstk_ms [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:132] # 1 __pformat_int.isra.0 [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:138] # 2 __mingw_pformat [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:138] # 3 __mingw_vfprintf [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:138] # 4 printf # 5 main Note: #0:00:00.135 in thread 18604 Note: 0x000000164a9ffa50 refers to 8 byte(s) beyond the top of the stack 0x000000164a9ffa58 Note: instruction: or $0x0000000000000000 (%rcx) -> (%rcx) Error #3: UNINITIALIZED READ: reading register rcx # 0 __pformat_int.isra.0 [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:138] # 1 __mingw_pformat [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:138] # 2 __mingw_vfprintf [../../../../../src/gcc-11.2.0/libgcc/config/i386/cygwin.S:138] # 3 printf # 4 main Note: #0:00:00.135 in thread 18604 Note: instruction: test %rcx %rcx Error #4: POSSIBLE LEAK 98 direct bytes 0x00000153bd9001c0-0x00000153bd900222 + 0 indirect bytes # 0 replace_malloc [d:\a\drmemory\drmemory\common\alloc_replace.c:2580] # 1 msvcrt.dll!malloc_crt # 2 msvcrt.dll!_setargv # 3 msvcrt.dll!_getmainargs # 4 pre_cpp_init # 5 msvcrt.dll!initterm # 6 __tmainCRTStartup # 7 .l_start # 8 ntdll.dll!RtlUserThreadStart =========================================================================== FINAL SUMMARY: DUPLICATE ERROR COUNTS: Error # 1: 2 Error # 2: 2 SUPPRESSIONS USED: ERRORS FOUND: 2 unique, 4 total unaddressable access(es) 1 unique, 1 total uninitialized access(es) 0 unique, 0 total invalid heap argument(s) 0 unique, 0 total GDI usage error(s) 0 unique, 0 total handle leak(s) 0 unique, 0 total warning(s) 0 unique, 0 total, 0 byte(s) of leak(s) 1 unique, 1 total, 98 byte(s) of possible leak(s) ERRORS IGNORED: 3 unique, 3 total, 113 byte(s) of still-reachable allocation(s) (re-run with "-show_reachable" for details) Details: C:\Users\dmn\AppData\Roaming\Dr. Memory\DrMemory-CControl.exe.9640.000\results.txt
Phidget API 22 : libusb deadlock
I currently have a thread of the Phidget API which deadlocks; here is a stack trace of my main thread: 1 __lll_lock_wait 0x7ffff5b3173c 2 __lll_lock_elision 0x7ffff5b343c7 3 mos_mutex_lock mos_lock-pthread.c 288 0x7fffd64b50ee 4 StartCentralThread phidget22.c 205 0x7fffd64d45dd 5 registerChannel phidget.c 1348 0x7fffd64d2432 6 Phidget_open_internal phidget.c 1416 0x7fffd64d2432 7 list_phidgets phidgets_parameter.hpp 1076 0x7fffd6139f9b /* list_phidgets is in my own code and calls Phidget_open(...) */ and an offending internal libphidget thread : 1 poll 0x7ffff12ba97b 2 ?? 0x7ffff54cb6ec 3 libusb_handle_events_timeout_completed 0x7ffff54cc76a 4 libusb_handle_events_completed 0x7ffff54cc8b0 5 ?? 0x7ffff54cd1d9 6 libusb_control_transfer 0x7ffff54cd539 7 libusb_get_string_descriptor_ascii 0x7ffff54ca47e 8 PhidgetUSBGetString usblinux.c 253 0x7fffd64d5319 9 scanVintDevices vint.c 218 0x7fffd64e5a2e 10 PhidgetManager_poll manager.c 380 0x7fffd64bc87c 11 CentralThreadFunction phidget22.c 371 0x7fffd64d4415 12 start_thread 0x7ffff5b2808c 13 clone 0x7ffff12c4e7f Phidget_open called from my main thread, opens a mutex also opened in CentralThreadFunction, and libusb_get_string_descriptor_ascii does not seem to return which deadlocks my whole app. What can I do ?
PC=0x00000000, corrupt stack in gdb, but FreeRTOS thread is still running fine on STM32
I'm developing a multi threaded application with FreeRTOS on a STM32. When I try to debug it with OpenOCD and gdb, I can do so with all threads but my main loop. >>> info threads Id Target Id Frame 6 Thread 536892936 (cli) vTaskSuspend (xTaskToSuspend=<optimized out>) at /home/user1273684/dev/firmware/module/FreeRTOS/Source/tasks.c:1620 5 Thread 536888728 (wifi_loop) vTaskSuspend (xTaskToSuspend=<optimized out>) at /home/user1273684/dev/firmware/module/FreeRTOS/Source/tasks.c:1620 4 Thread 536884824 (Tmr Svc) xTaskResumeAll () at /home/user1273684/dev/firmware/module/FreeRTOS/Source/tasks.c:2126 3 Thread 536905240 (main_loop) 0x00000000 in ?? () 2 Thread 536879832 (wifi_watchdog) xTaskResumeAll () at /home/user1273684/dev/firmware/module/FreeRTOS/Source/tasks.c:2126 * 1 Thread 536882960 (IDLE : : Running) prvIdleTask (pvParameters=<optimized out>) at /home/user1273684/dev/firmware/module/FreeRTOS/Source/tasks.c:3145 >>> thread 3 [Switching to thread 3 (Thread 536905240)] #0 0x00000000 in ?? () >>> bt #0 0x00000000 in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) I tried increasing the stack size (vTaskList() says there is plenty of space left, configCHECK_FOR_STACK_OVERFLOW is set to 2 and vApplicationStackOverflowHook() is never triggered) but without any change. 2017-06-20 10:34:34,217 - INFO # cli R 1 922 5 2017-06-20 10:34:34,217 - INFO # IDLE R 0 235 2 2017-06-20 10:34:34,218 - INFO # wifi_watchdog B 1 231 8 2017-06-20 10:34:34,218 - INFO # main_loop B 2 2879 6 2017-06-20 10:34:34,218 - INFO # Tmr Svc S 4 320 3 2017-06-20 10:34:34,218 - INFO # wifi_loop S 3 627 4 What is going on here?
Data Structure for Sequence of Event Analysis in R
The code below creates a sample dataframe to illustrate my problem. I have a time stamped list of events. set.seed(100) mydf<-data.frame(time=(1:1000),event = sample(1:10,10000,replace=TRUE)) mydf time event 1 6 2 5 3 7 4 8 5 4 6 2 7 10 8 9 9 4 10 6 11 4 12 3 13 8 14 3 15 9 16 1 17 7 18 3 19 8 20 10 I am trying to create a new variable that lists the previous events in a specified window. say the window is size 10. I would like to create the dataframe below. My ultimate goal is to prepare my data for sequence of events analysis. time event eventList 1 6 NA 2 5 NA 3 7 NA 4 8 NA 5 4 NA 6 2 NA 7 10 NA 8 9 NA 9 4 NA 10 6 NA 11 4 {6,5,7,8,4,2,10,9,4,6} 12 3 {5,7,8,4,2,10,9,4,6,4} 13 8 {7,8,4,2,10,9,4,6,4,3} 14 3 {8,4,2,10,9,4,6,4,3,8} 15 9 {4,2,10,9,4,6,4,3,8,3} 16 1 {2,10,9,4,6,4,3,8,3,9} 17 7 {10,9,4,6,4,3,8,3,9,1} 18 3 {9,4,6,4,3,8,3,9,1,7} 19 8 {4,6,4,3,8,3,9,1,7,8} 20 10 {6,4,3,8,3,9,1,7,8,10}
The last three rows do not match , could you please check your expected output mydf=read.table(text=" time event 1 6 2 5 3 7 4 8 5 4 6 2 7 10 8 9 9 4 10 6 11 4 12 3 13 8 14 3 15 9 16 1 17 7 18 3 19 8 20 10",header=TRUE,stringsAsFactors=FALSE) windowSize = 10 mydf$eventList = do.call(rbind,lapply(mydf$time,function(x) { ifelse(x<windowSize,NA,paste0("{", paste0(mydf[ tail(1:x,windowSize) ,"event"],collapse=",") , "}")) })) mydf # time event eventList #1 1 6 <NA> #2 2 5 <NA> #3 3 7 <NA> #4 4 8 <NA> #5 5 4 <NA> #6 6 2 <NA> #7 7 10 <NA> #8 8 9 <NA> #9 9 4 <NA> #10 10 6 {6,5,7,8,4,2,10,9,4,6} #11 11 4 {5,7,8,4,2,10,9,4,6,4} #12 12 3 {7,8,4,2,10,9,4,6,4,3} #13 13 8 {8,4,2,10,9,4,6,4,3,8} #14 14 3 {4,2,10,9,4,6,4,3,8,3} #15 15 9 {2,10,9,4,6,4,3,8,3,9} #16 16 1 {10,9,4,6,4,3,8,3,9,1} #17 17 7 {9,4,6,4,3,8,3,9,1,7} #18 18 3 {4,6,4,3,8,3,9,1,7,3} #19 19 8 {6,4,3,8,3,9,1,7,3,8} #20 20 10 {4,3,8,3,9,1,7,3,8,10}
I am assuming someone will come up with a more R way of going this, reducing your runtime. Meanwhile you can try this: for (i in 1:nrow(mydf)){ if(i<=w){ mydf$eventList[i] = NA } else { mydf$eventList[i] = list(mydf$event[c((i-w):i)]) } }
Understanding the processed hello world source code in C [duplicate]
This question already has answers here: What is the meaning of lines starting with a hash sign and number like '# 1 "a.c"' in the gcc preprocessor output? (3 answers) Closed 8 years ago. I have a hello world program of the source code in C of the following: For #include <stdio.h> #define MESSAGE "Hello, world!" int main() { puts(MESSAGE); return 0; } Now if we preprocess the source code by gcc, we get in front: # 1 "hello-world.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "hello-world.c" # 1 "/usr/include/stdio.h" 1 3 4 # 28 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 361 "/usr/include/features.h" 3 4 # 1 "/usr/include/sys/cdefs.h" 1 3 4 # 365 "/usr/include/sys/cdefs.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 366 "/usr/include/sys/cdefs.h" 2 3 4 # 362 "/usr/include/features.h" 2 3 4 # 385 "/usr/include/features.h" 3 4 # 1 "/usr/include/gnu/stubs.h" 1 3 4 My question is apparently, # 1 gets repeated, and so on. So what does this mean? What would # 28 and # 365 and # 385 mean?
Those are source line numbers in the given files. For example, # 28 "/usr/include/stdio.h" 3 4 precedes lines that originated in line 28 of stdio.h. You can read more by GCC's preprocessor output here. The format for the lines you've shown is: # linenum filename flags