- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm new to linking, and something tells me this is not the way to do it.
Any help would be appreciated.
[bash]#includeEDIT: The above program is wrong. It's not the way allocation is done for scalable_allocator. See the following posts for the correction.
#include
using namespace std;
using namespace tbb;
class SomeClass
{
public:
double d;
};
int main()
{
int* i = scalable_allocator().allocate( sizeof(int) );
SomeClass* s = scalable_allocator().allocate( sizeof(SomeClass) );
cout<<"Memory allocated"<
scalable_allocator().deallocate( i, sizeof(int) );
scalable_allocator().deallocate( s, sizeof(SomeClass) );
cout<<"Memory deallocated"<}[/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_debug.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_debug.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy_debug.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy_debug.so.2
But it doesn't work:
g++ -ltbb -L/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so.2 -o scalableAllocator scalableAllocator.cpp
You do not need to link with *proxy* files; otherwise your understanding is correct. The way to do this is either adding -ltbbmalloc (minus, non-capital L, tbbmalloc)to the list of options or adding one of the libraries as an input file (without -L or -l prefix for options). The line you tried did not work because you added -L to the file name.
Read more about -L and -l options of the compiler and linker.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tbb library is linked using -ltbb:
g++ -O3 -DNDEBUG -m64 -o pover ../../common/gui/xvideo.cpp pover_video.cpp polymain.cpp polyover.cpp -ltbb -ltbbmalloc -lpthread -lrt -lpthread -L/usr/X11R6/lib64 -lX11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
or link library statically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I type:
echo $LD_LIBRARY_PATH
I get this:
/opt/intel/tbb/tbb30_20100406oss/lib/intel64/cc4.1.0_libc2.4_kernel2.6.16.21:/opt/intel/tbb/tbb30_20100406oss/lib/intel64/cc4.1.0_libc2.4_kernel2.6.16.21
When I try to compile with this:
g++ -ltbb -o scalableAllocator scalableAllocator.cpp
I get this:
/tmp/ccYyHk3R.o: In function `tbb::scalable_allocator
scalableAllocator.cpp:(.text._ZN3tbb18scalable_allocatorIiE8allocateEmPKv[tbb::scalable_allocator
/tmp/ccYyHk3R.o: In function `tbb::scalable_allocator
scalableAllocator.cpp:(.text._ZN3tbb18scalable_allocatorI9SomeClassE8allocateEmPKv[tbb::scalable_allocator
/tmp/ccYyHk3R.o: In function `tbb::scalable_allocator
scalableAllocator.cpp:(.text._ZN3tbb18scalable_allocatorIiE10deallocateEPim[tbb::scalable_allocator
/tmp/ccYyHk3R.o: In function `tbb::scalable_allocator
scalableAllocator.cpp:(.text._ZN3tbb18scalable_allocatorI9SomeClassE10deallocateEPS1_m[tbb::scalable_allocator
collect2: ld returned 1 exit status
I understand that I'll have to link to one of these files:
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_debug.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_debug.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy_debug.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy_debug.so.2
But it doesn't work:
g++ -ltbb -L/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so.2 -o scalableAllocator scalableAllocator.cpp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
g++-L/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/ -ltbb -o scalableAllocator scalableAllocator.cpp
g++-L/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/ -ltbbmalloc -o scalableAllocator scalableAllocator.cpp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_debug.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_debug.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy.so.2
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy_debug.so
/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc_proxy_debug.so.2
But it doesn't work:
g++ -ltbb -L/opt/intel/tbb/tbb30_20100406oss/lib/ia64/cc4.1.0_libc2.4_kernel2.6.16.21/libtbbmalloc.so.2 -o scalableAllocator scalableAllocator.cpp
You do not need to link with *proxy* files; otherwise your understanding is correct. The way to do this is either adding -ltbbmalloc (minus, non-capital L, tbbmalloc)to the list of options or adding one of the libraries as an input file (without -L or -l prefix for options). The line you tried did not work because you added -L to the file name.
Read more about -L and -l options of the compiler and linker.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay, so tbbmalloc is a library like tbb.
I had used -L after having a look at the man page. I thought it was about specifying the entire directory. Had another look. Concept clearer. Thank you so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The correct code would be (as a person on another website posted) as shown below. I thought scalable_allocator syntax was like malloc. Made me wonder why you decided to allow allocation of n number of objects this way?
Question: In the third line, a temporary object of SomeClass() gets created, right? Could that be avoided?
[bash]int numberOfObjectsToAllocateFor = 1; SomeClass* s = scalable_allocator().allocate( numberOfObjectsToAllocateFor ); scalable_allocator ().construct( s, SomeClass()); scalable_allocator ().destroy(s); scalable_allocator ().deallocate(s, numberOfObjectsToAllocateFor); [/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[c++]int numberOfObjectsToAllocateFor = 1; SomeClass* s = scalable_allocator().allocate( numberOfObjectsToAllocateFor ); scalable_allocator ().construct( s, SomeClass()); scalable_allocator ().destroy(s); scalable_allocator ().deallocate(s, numberOfObjectsToAllocateFor); [/c++]
class scalable_allocator provides STL-style interface for memory allocation. It's primary purpose is to be used with STL or TBB containers. If you need C-style interface, use scalable_malloc, scalable_free etc. functions.
The necessity to provide a value to the construct() method is also specified by the C++ standard; that's why you need a temporary in the line 3. For default construction, you can use so-called placement operator new:
[c++]new(s) SomeClass();[/c++]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]::new(s) SomeClass();[/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now I guess I can just overload 'new' in my class and use scalable_malloc as you suggested.
And vector allocations would go like this:
std::vector> v;
Cool! :)
@ilnarb:
Thanks for helping...you used a scope operator before new. May I know what that was for?
::new
Is it to say that it belongs to a local scope?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);} void construct( pointer p) {::new((void*)(p)) value_type();}[/cpp]

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page