object,null,garbage-collection,c++-cx,pin-ptr , How can I save a object, so that it won't get collected by the GC in C++/CX


How can I save a object, so that it won't get collected by the GC in C++/CX

Question:

Tag: object,null,garbage-collection,c++-cx,pin-ptr

This is the code that I have for the constructor:

LmiVideoCapturer* LmiVideoCapturerConstruct_(LmiVideoCapturer* x, const void* implementation)
{
std::vector<LmiVideoCapturerInfo> &deviceList = LmiVideoCapturerDeviceList::Instance();
LmiVideoCapturerInfo &capturerInfo = LmiVideoCapturerInfo();
for (std::vector<LmiVideoCapturerInfo>::iterator it = deviceList.begin(); it != deviceList.end(); it++){
    if (LmiStringCompare(&it->uniqueId, &x->uniqueId) == 0){
        capturerInfo = *it;
        break;
    }
}

if (capturerInfo.uniqueId.size > 0){
    x->isBuiltin = LMI_TRUE;

    // set basic device info 
    LmiStringAssign(&x->name, &capturerInfo.name);
    LmiStringAssign(&x->model, &capturerInfo.model);
    LmiStringAssign(&x->manufacturer, &capturerInfo.manufacturer);
    x->position = capturerInfo.position;

    // set video capabilities
    LmiAllocator *a = LmiMallocAllocatorGetDefault();
    Platform::String ^deviceId = LmiStringWinRTString(&capturerInfo.uniqueId, a);
    XTRACE(L"=========================Will call from LMIVideoCapturerConstruct\n");
    LmiVideoCapturerWinRTImplementation ^impl = ref new LmiVideoCapturerWinRTImplementation(deviceId);
    if (impl->Initialize()){
        //TODO will need to save impl inside a pin_ptr (pinned pointer) so it will not be deconstructed by the GC
        x->implementation = reinterpret_cast<void*>(impl);
        LmiVideoCapturerCapability capability;
        LmiVideoCapturerCapabilityConstructDefault(&capability, a);
        capability.height = impl->encodingProfile->Video->Height;
        capability.width = impl->encodingProfile->Video->Width;
        LmiMediaFormat format; 
        LmiMediaFormatConstructFromNative(&format, impl->encodingProfile->Video->ProfileId);
        LmiVectorPushBack(LmiMediaFormat)(&capability.formats, &format);
        double usecs = ((double)impl->encodingProfile->Video->FrameRate->Denominator / impl->encodingProfile->Video->FrameRate->Numerator) * LMI_USECS_PER_SEC;
        LmiTimeRange range;
        LmiTimeRangeConstruct(&range, LmiTimeUsecs(usecs), LmiTimeUsecs(usecs));
        LmiVectorPushBack(LmiTimeRange)(&capability.ranges, &range);
        LmiVectorPushBack(LmiVideoCapturerCapability)(&x->capabilities, &capability);

        return x;
    }

}

return nullptr;

}

Now I want to save "impl" somewhere, thats why I saved it in X that I will return at the end of the function. BUT as soon as this function is ended, a GC calls the deconstructor for this object. How can I set this object to be avoided by the GC, when it is called?

EDIT: After hours of searching on the internet I noticed that c++ has something called pinned pointers (pin_ptr) but all the examples I found on it, shows saving arrays of int inside. Is it possible to save a object inside a pinned pointer?


Answer:

There is no garbage collection in C++/CX.

The LmiVideoCapturerWinRTImplementation^ impl variable you defined is a smart pointer type that will automatically manage the lifetime of the object for you. More information on C++/CX types can be found here: http://blogs.msdn.com/b/vcblog/archive/2012/09/17/cxxcxpart02typesthatwearhats.aspx


Related:


Extending JFrame - how does “super” keyword work?


java,object,jframe,super
I've made a class that extends JFrame, and in my classes constructor, to set the title I can either use: super("title"); setTitle("title"); or just create a JFrame object i.e: JFrame f = new JFrame("title); How does the compiler differentiate from all of these to conclude the same thing? I know...

Object Variable or With Block Variable Not set in loop using find function


vba,excel-vba,loops,object,find
Sub Main() Dim FName As Variant, R As Long, DirLoc As String, i As Integer R = 1 i = 1 DirLoc = ThisWorkbook.Path & "\" 'location of files FName = Dir(DirLoc & "*.csv") Do While FName <> "" ImportCsvFile DirLoc & FName, ActiveSheet.Cells(R, 1) R = ActiveSheet.UsedRange.Rows.Count + 1...

Search inside objects javascript


javascript,object,firebase
I'm experimenting on login with firebase. I can make an account, and it'll store additional information too. The problem is retrieving this information. I can get it using: usersRef.on("value", function(snapshot) { console.log(snapshot.val()) }, function (errorObject) {...}); When I do this I get two things (because I have two accounts): -JrrzEOqZQU0HVeYVXCm:...

getting access to javascript object property beginning with number


javascript,object
I am calling an api which returns an object var rain = data[i].rain; $.get( "http://api.openweathermap.org/data/2.5/forecast?q=London,uk&mode=json&units=metric", function( data ) { var data = data.list; for(var i = 0; i < 12; i++){ var rain = data[i].rain; console.log(rain) } }); rain returns the following when I inspect the console: Object {3h: 0.005}...

c++: Passing objects to functions


c++,templates,object
I was going through a code where I encountered some problem and was able to crack this piece of code: #include <iostream> #include <stdint.h> #include <unistd.h> #include <errno.h> #include <vector> #include <sys/types.h> using namespace std; class abc { public: abc(int x,int y) { cout << "x:" << x << endl;...

Need help converting JSON to C# Objects


c#,asp.net,json,object,serialization
I'm currently trying to convert a JSON string into C# objects and currently am experiencing trouble during my debugging. Below is a sample of the JSON along with my classes. Classes public class Timeline_RootObject { public List<Timeline_Frame> frames { get; set; } public int frameInterval { get; set; } }...

Spawn random objects without overlapping (Java)?


java,object,overlap,spawn
I'm developing a game in Java, and part of it requires that objects spawn at the top of the screen and proceed to fall down. I have three objects that can possibly spawn, and three possible x coordinates for them to spawn at, all stored in an array called xCoordinate[]....

How to get the public objects


php,object,guzzle,rackspace-cloud,rackspace
I'm working on PHP with Rackspace API, this is what I have used here: $file->setContent(fopen('sites/default/files/rackspace/' . $end_element, 'r+')); $cdnUrl = $file->getPublicUrl(); print_r($cdnUrl); And its returning me the below mentioned structure. Guzzle\Http\Url Object ( [scheme:protected] => http [host:protected] => something.r2.cf3.rackcdn.com [port:protected] => [username:protected] => [password:protected] => [path:protected] => /something-abc.jpg [fragment:protected] =>...

Javascript - accessing an object with duplicate names


javascript,arrays,xml,object
I have an XML file that I read in to a Javascript object. This is called jsonXML. I can see the object in its entirety in the console when I log it. It is a pretty complex object with a lot of layers and duplication. I need to access some...

In Java, How do I cast a Realm Object into the class I wish to write to the Database?


android,class,object,casting,realm
I am currently working on a project where my Database has a very large number of tables (Approx 60 total). I am working to create the Database Helper class that will function as the writer/ reader to/ from the database. And example of my write method would be this: public...

Use of self when creating objects in Python


python,object,self
I made several classes which are doing the same thing, but I still don't completely understand the difference, and which is best to use. Also, the 4th object is not working. It says 'NameError: name 'self' is not defined', although I don't understand what is going wrong. This is what...

Object declaration in C++


c++,object,constructor
I have two questions about the following code in c++. What does the line A obj() in main() mean? Its not giving any error. And why does the next line obj.fun(); give the following error? request for member 'fun' in 'obj', which is of non-class type 'A()' The code is:...

Empty object in Javascript


javascript,object
I have a weird situation. I take some values from a form and save it in an object. I print out the values and it prints fine to the console log. But when I try to access it or print again in next line. It returns empty. Here is the...

How do I remove duplicate objects in an array by field in Javascript?


javascript,arrays,sorting,object
I have an array of objects: [{ id: 1, name: 'kitten' }, { id: 2, name: 'kitten' },{ id: 3, name: 'cat }] How do I remove the second kitten? Sorting into an array of names doesn't work, because I can't know if I am deleting id 1 or or...

Don't run Object animator [closed]


java,android,object,objectanimator,animator
Why this code don't run? When run the app, i faced with stopped app error message.. ImageButton img=(ImageButton)findViewById(R.id.img0); ObjectAnimator[] imganim = new ObjectAnimator[10]; imganim[0].setTarget(img); ...

Get and add all properties of type Mname from a list of objects and add them dynamically too a drop down


c#,linq,list,object,properties
Ok so I have an object type called monsters and a list of all monsters I need to get all the strings from the property called MName and add each one to a Drop down text box. here is the class so far.(sorry Im really new to coding.) using System;...

Socket.io error in sending arrays


javascript,arrays,object,socket.io
I have 3 variables to send to the client using socket.io, namely, mapRes & location. server.js var mapRes = {width : 720, height: 1040}; var location = [{x:100,y:100,z:100},{x:200,y:200,z:200}]; var obj = {'1':{x:100,y:200}}, '2':{x:200,y:100}}; io.on("connection", function(socket){ socket.emit("mapRes",mapRes); socket.emit("location",location); socket.emit("object",obj); } client.html socket.on('mapRes',function(message){ var mapRes = message; console.log(mapRes); }); socket.on('location',function(message){ var location...

Dynamically create all objects contained in file


java,object,dynamically-generated
I am developing a program to mark algorithms submitted by a group of students; each student will submit their own .java files. I would like to place these .java files into a folder and run my program. My program would then instantiate each class in the folder and add it...

Differences between null and StringUtils.isBlank()


java,null
I want to check if a String is empty or not and I would like to know the differences between the following and which one is better and on which occasions. Specially because I'm getting this error if I use "isNotBlank": "cannot be cast to java.lang.String". this.text.getData() != null <---...

I'm using AngularFire, How can I retrieve this “email”, “uid” data?


angularjs,object,firebase,angularfire
JS CODE var myFirebaseRef = new Firebase('https://blinding-inferno-7068.firebaseio.com/'); var createdUserRef = myFirebaseRef.child('users').child('createdUser'); $scope.users = $firebaseArray(createdUserRef); HTML CODE <ul ng-repeat="user in users"> <li>{{user.uid}}</li> <li>{{user.email}}</li> <li>{{user}}</li> </ul> What I wanted was user.uid and user.email, but those thing didn't come out. So I checked the user object, and these things came out....

Matlab - object orientated with abstract Interface - How creating object?


matlab,object
Hello lovely community, i am quite new here, but still hope someone can help me out. I just worked a bit with Matlab in the past and want to do a new project. Earlier I just stored all in one Matlab file and didn't had the need to use classes....

Object Read-Only Properties


javascript,object
I was reading this question about read-only properties, and I came upon this snippet: var myObject = { get readOnlyProperty() { return 42; } }; alert(myObject.readOnlyProperty); // 42 myObject.readOnlyProperty = 5; // Assignment is allowed, but doesn't do anything alert(myObject.readOnlyProperty); // 42 Now, I know to hide the scope, you...

Trying to get property of non-object (valid json) [duplicate]


php,json,object
This question already has an answer here: How can I access an array/object? 3 answers Just a real quick question please, I have this string that came from my query I am able to display the string using xx = dd($sumx) which gave me the string below: string(124) "[{"total":-4107717.58,"alerx":4,"currentYear":-4107717.58,"lastYear":0,"date":2015,"value":{"debit":0,"credit":4107717.58}}]"...

Excel vba code using ThisWorkbook.Sheets(1).Range not working, but Sheet1.Range works fine. Why?


excel,vba,excel-vba,object
When I use wb.Sheets(1).Range("A:A").Find(What:=ID, LookIn:=xlValues) I get error 91 - Object Variable or With Block not set. When I use Sheet1.Range("A:A").Find(What:=ID, LookIn:=xlValues) it returns correct value. Why the difference? Is there a flowchart I can reference or any simple information available to understand which sub-commands (I don't know the proper...

Object returns null


java,object,null
Summary: New to Java, tried looking through other posts but didn't find an answer. I'm learning inheritance and have an AddressBook class extended by a Runner class. When I write a program to test the inheritance I create a Runner object. If I get the first String parameter it returns...

Avoid EF update the null image to database in .Net MVC


asp.net-mvc,entity-framework,null,edit,httppostedfilebase
In my SachController, there is an Edit method like below. In the view, there are several textbox and one file-input for upload image object. Sometime, user doesn't want to change the image and they just don't select a new image. And the image (HttpPostedFileBase) is null. How can I avoid...

Java- HashMap.get returns null when it shouldn't


java,android,null,hashmap
I am using a HashMap to link some strings to integers, which are then used to index a list. The strings I am using in .get() are passed to a method, from an android spinner, and are definitely correct as I outputted them to the log, and they match those...

Return two separate arrays from an object in JavaSript


javascript,arrays,object
I need to complete the keysAndValues function so that it takes an object and returns the keys and values as separate arrays. For example: keysAndValues({k: 11, l: 12, m: 13}) // should return [['k', 'l', 'm'], [11, 12, 13]] I have already tried: http://jsfiddle.net/marcusdei/ppfh5fpa/4/...

Is a Java class variable a reference to a class object?


java,class,object,reference
I know such question has been asked before but I couldn't find a satisfactory answer. Assume a java class : class Foo{ public int k; Foo(int a){ k=a; } } class My{ public static void main(String args[]){ Foo obj = new Foo(5);//1 obj=new Foo(8); //2 } } I want to...

Persist Object's value after copying in Java


java,object
My sample code - private final DataObj dataObj = getDataObjs(); private final DataObj dataObj1 = new DataObjImpl(); dataObj1 = dataObj; //I need the value of dataObj1 to be the same even if the value of dataObj is modified anywhere further down in a class. My problem is that if the...

Changing the property values of an object in an array using another property value


javascript,arrays,object
I have an array as below. What I'd like to implement is a function that takes the node's ID, x and y as its inputs and make changes accordingly in the array. var nodes = [{ID:"101", x:100, y:200} ,{ID:"102", x:200, y:200} ,{ID:"103", x:300, y:300} ,{ID:"104", x:200, y:300}]; For example, function...

Parsing JSON object within a JSON response [duplicate]


javascript,json,object
This question already has an answer here: Access / process (nested) objects, arrays or JSON 6 answers I'm trying to get a bit of javascript working to pull back a currency conversion. Using the API from fixer.io, I'm requesting http://api.fixer.io/latest?symbols=USD&base=GBP I get an object back, but I don't know...

Filter array of objects with another array of objects


javascript,jquery,arrays,object,filter
This question is similar to this one Jquery filter array of object with loop but this time I need to do the filter with an array of objects. Exemple: I have an array of objects like this: myArray = [ { userid: "100", projectid: "10", rowid: "0" }, { userid:...

Is it possible to create a queue of object arrays in C++?


c++,arrays,object,queue
For example: class Hooks { public: std::string text; std::string hookfont; HookFromEncouter() { text = "Would you befriend an elf? "; hookfont = "COPRGTB.ttf"; } HookFromEncouter(string text1, string hookfont1) { text = text; hookfont = hookfont1; } }; I need to store arrays of this object in a queue: How do...

Object property is undefined


javascript,object,gulp
I don't know if I'm missing something here, but for some reason a configuration object I create is always undefined upon using: gulpfile.config.js var config = { src_path: "Client/" }; gulpfile.js var config = require("./gulpfile.config.js"); gulp.task("test", function() { util.log(config.src_path); // results in 'undefined' }); Do objects have to be initialized...

Run class methods in different threads


java,multithreading,object,methods
Let's suppose I have this class: public class Myclass { method1(); method2(); method3(); } I want to know if there's a way to run all 3 methods in different threads simultaneously. Is there a way to create a class MyThread : public class MyThread{ //implementation } in way that it...

Multiple NULL addition into a List in Java


java,list,concurrency,null,add
I have 2 lists and want to copy some element from one to another, i.e. there are old and new employees list I need to union 2 lists and delete the elements that include to the old list but not include in the new one. I could solve the part...

Creating javascript dates object


javascript,date,object
I am trying to create an object with all the dates from "today" until 60 days from now. My code: var dates = []; getDateRange(); function getDateRange() { var today = new Date(); var date = new Date(); for (var i = 0; i <= 59; i++) { date.setDate(today.getDate()+i); console.log(date);...

Sort when values are None or empty strings python


python,list,sorting,null
I have a list with dictionaries in which I sort them on different values. I'm doing it with these lines of code: def orderBy(self, col, dir, objlist): if dir == 'asc': sorted_objects = sorted(objlist, key=lambda k: k[col]) else: sorted_objects = sorted(objlist, key=lambda k: k[col], reverse=True) return sorted_objects Now the problem...

Access object variables dynamically in php


php,object
There are multiple response type from my service provider and that is why i created a config array like below. $configArray = array( 'type_1' => array( 'name' => array('parent', 'user', 'profile', 'name', 'fullName') ), 'type_2' => array( 'name' => array('parent', 'person', 'info', 'basic', 'name') ) ); So if the return...

meaning of the super keyword in the parent class python


python,object,super
I do not understand the meaning of the super keyword when it is not used in a child class. The question comes from this class here that I found on a git hub project where I am working (the link is https://github.com/statsmodels/statsmodels/pull/2374/files) Look for example at the fit method where...

How to iterate an object and build a new one


javascript,object,nested
I am using JavaScript to iterate customers in an object which is constructed as follows: [ { "customer": "Customer 1", "project": "1" }, { "customer": "Customer 2", "project": "2" }, { "customer": "Customer 2", "project": "3" } ] I wish to build a new object in iteration which would be...

ActionScript: How to call an objects function within an array?


arrays,flash,object,actionscript
In Java it is possible to set the datatype of an array, and by setting the datatype to the object I am using, I can call the methods and variables of that object. For instance: ArrayList<Object> name = new ArrayList<Object>(); name.add(new Object(variables)); name.get(0).method; Is there any way I can do...

Swift won't allow me to use `!=`


ios,swift,if-statement,null
Currently trying to check if three values, that I just converted from Strings to doubles, are nil from the UITextFields aValue, bValue, and cValue. I don't get a compile error from these variables until the if statement at the bottom of the code block (shown below) where it causes a...

Creation of object using abstraction fails, likely a simple fix I cannot see


java,object,constructor,abstraction
A novice question about abstraction and constructors. I feel like I'm missing something obvious. I have an abstract class Piece, this is the constructor: public abstract class Piece { private int[] location = new int[2]; private final char color; public Piece(char color, int[] location) { this.location = location; this.color =...

Javascript Sorting Array of Objects [duplicate]


javascript,arrays,sorting,object
This question already has an answer here: Sorting an array of JavaScript objects 14 answers (Please excuse any errors - this is my first post and I am also relatively new to Javascript) I'm trying to sort an array of objects by a specific property value in Javascript. I...

Object.length undefined in javascript [duplicate]


javascript,arrays,object
This question already has an answer here: Length of a JavaScript object (that is, associative array) 21 answers I have an javascript object of arrays like, var coordinates = { "a": [ [1, 2], [8, 9], [3, 5], [6, 1] ], "b": [ [5, 8], [2, 4], [6, 8],...

Dynamic creation of objects vs storing them as fields


java,performance,object
I have this loop which runs about 1,000,000 times. while ((line = br.readLine()) != null) { if(!(line.isEmpty())){ data = new JSONObject(line); name = (String)data.get("name"); surname = (String)data.get("surname"); ar.put(name, surname); //an array } } What are the advantages (if any) in terms of efficiency of having it like that were data,name...

Jackson - Extract Data without Brackets, Commas, and =?


java,json,object,jackson,jackson-modules
I don't know a ton about Jackson, I'm just using it because I needed to share data from Python to Java. Anyway my code is pretty simple ObjectMapper mapper = new ObjectMapper(); Map<String,Object> data = mapper.readValue(new File(FileName), Map.class); System.out.println(data.get("SomeInput")); This is what I'm getting: {Y=0.830168776371308, Z=0.16877637130801687, X=0.0010548523206751054} I really just...