// MEMBER FUNCTION
void Trick::MemoryManager::clear_var( void* address) {

    ATTRIBUTES* reference_attr;
    ALLOC_INFO* alloc_info;

    pthread_mutex_lock(&mm_mutex);
    alloc_info = get_alloc_info_at( address);
    if (alloc_info != NULL) {
        reference_attr = make_reference_attr( alloc_info);
        if (alloc_info->type == TRICK_STRUCTURED ) {
            if (alloc_info->num_index != 0) {
                clear_arrayed_class( (char*)(alloc_info->start), reference_attr, 0, 0) ;
            } else {
                clear_class( (char*)(alloc_info->start), alloc_info->attr) ;
            }
        } else {
            clear_rvalue( alloc_info->start, reference_attr, 0, 0 );
        }
        free_reference_attr( reference_attr);
    } else {
        std::stringstream message;
        message << "Cannot clear the variable at address " << address
                << "because memory manager knows nothing about it." ;
        emitError(message.str());
    }
    pthread_mutex_unlock(&mm_mutex);
}
示例#2
0
void Trick::DataRecordGroup::register_group_with_mm(void * address , const char * type) {
    // Only add to the memory manager if it has not already been added
    if ( TMM_var_exists(name.c_str()) == 0 ) {
        // Declare this to the memory manager.  Must be done here to get the correct type name
        TMM_declare_ext_var(address , TRICK_STRUCTURED, type , 0 , name.c_str() , 0 , NULL ) ;
        ALLOC_INFO * alloc_info = get_alloc_info_at(address) ;
        alloc_info->stcl = TRICK_LOCAL ;
        alloc_info->alloc_type = TRICK_ALLOC_NEW ;
    }
}
int Trick::MemoryManager::is_alloced(void *addr) {

    ALLOC_INFO *info;

    pthread_mutex_lock(&mm_mutex);
    if ( (info = get_alloc_info_at( addr)) != NULL) {
        pthread_mutex_unlock(&mm_mutex);
        return (1);
    }
    pthread_mutex_unlock(&mm_mutex);
    return (0);
}