Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #81488
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Memory allocator |
| Date | 2021-09-23 21:59 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <siimbj$jd$1@dont-email.me> (permalink) |
| References | <dae5bfd7-9f2c-4f1a-90bc-8e15125e6617n@googlegroups.com> <sii8na$s3o$1@dont-email.me> <AC23J.143094$o45.68989@fx46.iad> |
On 23 Sep 2021 19:15, Scott Lurndal wrote: > "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes: >> On 23 Sep 2021 16:46, Ayush Anshul wrote: >>> Consider me a C++ noob and go easy on me :| >>> >>> Suppose I have a package code and a product code on top of it. >>> I have control only over the package code side of things. My >>> memory is allocated/monitored via product code. Can >>> I override new/malloc on my side to get all allocations done via >>> that product code function or something similar >>> >>> One way I know is that they override global new/malloc on their end. >>> Other way is I write custom allocator, and use it everywhere(where I >>> have there allocator function registered as a callback). >>> >>> Is there some other easier way? >>> >> >> At the C++ level you can define `operator new` and `operator delete` >> (plus array variants) in each class. >> >> For a Windows DLL you can override `malloc` internally in the DLL, but a >> Unix shared library is more like a static library, not separate from the >> client code, so you can't do that with a shared library. > > By why criteria do you consider a unix shared object to be anything like > a static library? > > "malloc" is a "weak" symbol in all modern unix systems, which means that > the symbol can be overridden by the application if desired. The OP is interested in overriding it locally in his library (to be precise the OP calls it a "package", I presume that's a library). A Windows DLL supports that local override where the library uses one variant of `malloc` while the client code, the app, uses another. I believe, but please correct me if I'm wrong, that you can't do that with a Unix shared library? - Alf
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Memory allocator Ayush Anshul <ayushanshul07@gmail.com> - 2021-09-23 07:46 -0700
Re: Memory allocator "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-23 18:07 +0200
Re: Memory allocator scott@slp53.sl.home (Scott Lurndal) - 2021-09-23 17:15 +0000
Re: Memory allocator "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-23 21:59 +0200
Re: Memory allocator scott@slp53.sl.home (Scott Lurndal) - 2021-09-24 14:58 +0000
Re: Memory allocator "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-24 18:55 +0200
Re: Memory allocator scott@slp53.sl.home (Scott Lurndal) - 2021-09-24 17:23 +0000
csiph-web