Is it necessary to use xlib's "XAllocSizeHints()"?

359 views Asked by At

Xlib has a function called XAllocSizeHints to allocate a XSizeHints structure on the heap and set it to zero.

XSizeHints *sizehints;
sizehints=XAllocSizeHints();

However, is it necessary to always use this function? Or can I do this:

XSizeHints sizehints;
memset(&sizehints, 0, sizeof(XSizeHints));

I would like to know if it is possible to avoid XAllocWMHints and XAllocClassHint too.

2

There are 2 answers

1
Havoc P On BEST ANSWER

It's fine to stack allocate these (as long as you don't keep them around after the current function returns of course). There's no magic in those alloc functions. In fact most code probably does allocate them on the stack.

0
AudioBubble On

It's actually better to use memset way, because if you call XAllocSizeHints() then you need to explicitly free memory with XFree().